Table of Contents
How to add a new model
- Create the models folder
If you haven’t already, you will need to create the models folder. This is where our model files will go. In our testing, we created:
/components/com_helloworld/models - Create <view>.php within models folder
Each component view can have a corresponding model. In this tutorial we are creating a model for our helloworld view, so we will be creating
/components/com_helloworld/models/helloworld.php
In this file, place the following code:
- Update your view.html.php file to call the getMsg() function
In our components/com_helloworld/views/helloworld/view.html.php file,
we originally created the “Hello World” message via the following line:We will replace this line of code with the following:
The view.html.php file will now look like the following:
Our new model in action
As you can see in the screenshot below, our new model comes into play when our view calls one of the model’s functions.
View | When our view calls | $this->get(‘Msg‘); |
---|---|---|
Model | … the following fuction is run in our model: | getMsg() |
good work, thx for this.
next step (pls 🙂 -> build router and redirect between views with parameter
very useful and understandable tutorial. thx for this, pls continue.
The best explanation i ever found. Thank you.
Pleas continue.
Really good set of tutorials.
Can I suggest , helper files for the next as shis would finsish off a lot of the front end component process and be really helpful addition the the model
anonyme, as this article was initially written nearly 3 full years ago, I don’t think there are going to any more articles anytime soon.
thank u for the joomla component graphical explanation…
many many thanks
By
P.PRASAD