Advertisement

How to load an extra model in a view?

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
JanoD
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Tue May 07, 2024 5:12 pm

How to load an extra model in a view?

Post by JanoD » Mon Nov 04, 2024 7:26 pm

Hi,

I created a component with a view called e.g. "MyView" and associated default model "MyViewModel.php". In "MyView/HtmlView.php" I want to load the default model and also an extra additional model called "MyView2Model.php".

Doing

Code: Select all

$model1 = $this->getModel('MyView');  
works and creates an object. Loading the second model

Code: Select all

$model2 = $this->getModel('MyView2');
gives NULL. Any idea what is wrong? I assume all the paths and naming conventions are correct. If I rename the second model to "MyView" and change the name of the class accordingly than the model loads flawlessly.

Doe it mean that I can use only one model per view?

Thanks!

Advertisement
SharkyKZ
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3098
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: How to load an extra model in a view?

Post by SharkyKZ » Mon Nov 04, 2024 8:21 pm

In core components model instances are set on the view in the controller. Call $view->setModel($model) after creating the view in the controller.

JanoD
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Tue May 07, 2024 5:12 pm

Re: How to load an extra model in a view?

Post by JanoD » Tue Nov 05, 2024 1:29 pm

While I will try this direction on my own, could you provide me with an example how to do this in a controller or point me to a tutorial? This would be very helpful, thanks!

Advertisement

Post Reply

Return to “Joomla! 4.x Coding”