3

I have created a component using http://component-creator.com/

I have got two tables #__competition_data & #__competition_entries.

I also have an empty view

The #__competition_data table is where the competitions are added (in the backend) and the #__competition_entries is where the entries are stored, from a front end form.

In my empty view, I want to be able to display the _data (showing title of competition etc) and have the form (from the _entries) displayed underneath.

I have a premium account with Component-Creator, but they're saying they can no longer help me with my support request (which I think is a breach of contract - but that's another story).

I know I need to edit:

models/frontendv1ewform.php
view/frontendv1ewform/view.html.php
view/frontendv1ewform/tmpl/default.php

But I can't seem to work out where I'm going wrong. I have read the docs on Joomla.org but still can't work it out! Any ideas where I'm going wrong?

  • Can you provide more information about where you are? Is data getting into the tables? Are you seeing errors? Does the view display the data you expect to see? – user101289 Jun 27 '14 at 17:34
  • Thanks for your reply. I can get the form to display within the frontend correctly, this the populates the table once the form is filled in. I can't however get the data (from the _data table to display in the front end) – RustyJoomla Jun 30 '14 at 8:38
3

If I got this right, you want to have a list of data from one table together with a form for the other table in the same view. This sort of views is not the easiest task because it makes use of multiple models. That's very likely out of the scope of what component-creator is built for and thus they don't give you support anymore. That's understandable.

If this is your first component, then I'd advise you to look for a different approach. Like loading the form by clicking on a button (maybe in a modal). Then it's easy because the form will be a regular form view and you have a regular view list of data.

If you are more familiar with Joomla MVC, you can assign two models within your controller and load the needed data from those in your view.

In my component I did it in my main controller (controller.php) in the display method based on the active view. Something like this:

// Add additional models
$viewName       = $this->input->get('view', 'default_view');
$format         = $this->input->get('format', 'html');

switch ($viewName)
{
    case 'foo':
        $viewLayout = $this->input->get('layout', 'default');
        $view = $this->getView($viewName, $format, '', array('base_path' => $this->basePath, 'layout' => $viewLayout));
        $view->setModel($this->getModel('foo'));
        $view->setModel($this->getModel('bar'));
        break;
    case '...':
        ...
        break;
}
  • Thanks for you reply. Yes you're right I want to take two models and within the controller and show to relevant data within the frontend view. But I can't work out how to get the models to load into the controller. – RustyJoomla Jun 30 '14 at 8:36
  • Added the code I use to add multiple models. There may be better ways of course :) – Bakual Jun 30 '14 at 12:38
  • Thanks for the reply and code. So I'd just need to replace getModel ('foo') and getModel ('bar') with my two models right? – RustyJoomla Jul 1 '14 at 5:48
  • Yep, just replace foo and bar with the names of your models. See api.joomla.org/cms-3/classes/JViewLegacy.html#method_setModel for the API. You can also define one of the models as the default one. – Bakual Jul 1 '14 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.