Hi,
Took me long enough to understand - here is a little diagram explaining how I think the model view controller works. (please correct me if you think that I am wrong!!)
Most of the components that I have found in Joomla! have static views as 'entry points' to the component. They have no model and are therefore static. Alternatively they have helper classes pulling content in (like the 'article' view of com_content. Once we are in the component, every form, every link points back to index.php and passes the paramters 'option' and 'task' to Joomla. (Either as hidden values in forms or url paramters on links.)
Once that's done, Joomla jumps the component which is defined in '$option'. Once we are there the controller matches the task value against a member function within its class. That function then pulls in the right model and view and tells the view which layout to use.
The view itself pulls in the data from the model to populate itself,
Is that correct?
P.S I am currently working on an example component. During that process I document my prgress on my blog. Once the component is finished (possibly Wednesday next week) I will offer the component as free download. Feel free to have a look already...
http://www.uwe-duesing.com/index.php/joomla-blog#component
Model View Controller
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
- uweD
- Joomla! Apprentice
- Posts: 39
- Joined: Mon May 14, 2007 9:38 pm
- Location: Auckland -- New Zealand
- Contact:
Model View Controller
Last edited by uweD on Mon Sep 17, 2007 8:52 am, edited 1 time in total.
Re: Model View Controller
You can also find a good introduction to MVC at:
http://en.wikipedia.org/wiki/Model_view_controller
They also have a diagram depicting the relationship of MVC.
Ian
http://en.wikipedia.org/wiki/Model_view_controller
They also have a diagram depicting the relationship of MVC.
Ian
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!
- jalil
- Joomla! Enthusiast
- Posts: 128
- Joined: Wed Jul 04, 2007 4:54 am
- Location: Kuala Lumpur, Malaysia
- Contact:
Re: Model View Controller
uweD wrote:Hi,
Took me long enough to understand - here is a little diagram explaining how I think the model view controller works. (please correct me if you think that I am wrong!!)
Most of the components that I have found in Joomla! have static views as 'entry points' to the component. They have no model and are therefore static. Alternatively they have helper classes pulling content in (like the 'article' view of com_content. Once we are in the component, every form, every link points back to index.php and passes the paramters 'option' and 'task' to Joomla. (Either as hidden values in forms or url paramters on links.)
Once that's done, Joomla jumps the component which is defined in '$option'. Once we are there the controller matches the task value against a member function within its class. That function then pulls in the right model and view and tells the view which layout to use.
The view itself pulls in the data from the model to populate itself,
Is that correct?
P.S I am currently working on an example component. During that process I document my prgress on my blog. Once the component is finished (possibly Wednesday next week) I will offer the component as free download. Feel free to have a look already...
http://www.uwe-duesing.com/index.php/joomla-blog#component
a very simplistic view as depicted in the link given above is M::C::V.
my understanding is this.
A model, think of it as a mathematical model if you like, defines and handles all the data. The view is self explanatory. And the controller sits in between controlling the process between the View and the Model. The challenge wuld be to make them as separate as possible. Idelly i may have a controller software at my place, and i may be using your database at your end, and we display according to the nice layouts made by some fashionable italian layout designer. That would be real MCV, yes. I say MCV because MVC isnt the correct order of alphabeths according to the concept itself, but perhaps it is already a convention to call it that.
so your diagram would be an extended version, and i worry about the portion where your model goes straight to the view. i do not think this is right. i think your model must talk to your controller first. and the controller talks to the view.
if there is a mistake in your model, there is no chance for the controller to select a different database, and present and unfailing view to the user. if the model talk to the controller, the controller would know of any undesirable event and can act upon it. it isnt appropriate for the view to do that.