Using multiple forms in same model/view using Joomla 2.5 MVC

1,475 views
Skip to first unread message

Qson

unread,
Jul 30, 2012, 8:17:31 AM7/30/12
to joomla-de...@googlegroups.com
Hi,
I have a component which manages a lot of projects. I have a list view (projects) and an item view (project). The item view uses a form (project.xml) combined with JControllerForm and JModelAdmin. This works excellent, but now I have another form and another layout for a project budget. I want to use the same model and view (different layout) since much of the data is the same. How do I best control which form is used? A "form" url parameter which is used in JModelAdmin::getForm to select which form is loaded? Or perhaps one getForm and one getBudgetForm in the model and override the JControllerForm::save to use the custom methods of the model?

Perhaps it will be best after all to use separate models/views for each form, project, project_budget, project_members, project_results, but there will be lots of views and lots of duplicated code, since all use data from the default project view.

Thanks in advance!

// Qson

elin

unread,
Jul 30, 2012, 10:48:09 AM7/30/12
to joomla-de...@googlegroups.com
You might want to look at how the profile plugin does this since it can be used to support many different profiles (each with a form) and you can insert one or more of  them dynamically. 

Elin
Message has been deleted

KHarmer

unread,
Aug 2, 2012, 6:34:17 PM8/2/12
to joomla-de...@googlegroups.com
Hi Qson,

You could try using mulitple layouts. Adding '&layout=LAYOUTNAME' to your URL parameters will call a specific layout from a view tmpl folder; not adding it will always call the default.php layout.

In your views 'view.html.php' file you could check for '&layout=LAYOUTNAME' using 'JRequest::getVar('layout');' and assign relevant data models - if needed.

I could put more detail here if u need but I can't now as I have to sleep!

Hope that helps,
K...

Andy Hickey

unread,
Mar 24, 2014, 8:58:03 AM3/24/14
to joomla-de...@googlegroups.com, kristia...@gmail.com
Hi qson,
I'm looking to do just that: to combine item and list views together in a custom component. If you could post any links or any code on how to achieve this I'd really appreciate it!
Andy

Andy Hickey

unread,
Mar 24, 2014, 9:04:34 AM3/24/14
to joomla-de...@googlegroups.com
Have you got an example of a component implementing multiple models in a single view? I'd love to see the code. Trying to get this working in a custom component myself
Andy

Dmitry Rekun

unread,
Mar 24, 2014, 11:34:15 AM3/24/14
to joomla-de...@googlegroups.com
Andy,

to achieve this you need to set your Models for the View using the Controller:

http://docs.joomla.org/Using_multiple_models_in_an_MVC_component

Dmitry
Reply all
Reply to author
Forward
0 new messages