The Joomla MVC classes |
Written by Administrator | ||||||
Wednesday, 03 March 2010 | ||||||
Page 1 of 5 You might know what the MVC pattern is all about, but to make the best of it in Joomla you need to understand the three MVC classes it provides. Joomla is an object-oriented system that uses the MVC – Model, View Controller – design pattern wherever it possibly can. For example, you can use the MVC approach when you are building a new module, component or plug in and its also used in most of the important inner workings of Joomla. However while the MVC idea is simple enough the proliferation of classes and objects in use can make it seem complicated so let's see if it can be made clear. Simple MVCThe first thing to say is that Joomla's approach is MVC plus a little. In traditional MVC designs there are just three objects:
This is the rough fundamental idea that then goes on to be interpreted in lots of different ways. Don't expect to encounter a single authorativite way to define and build MVC applications – it's all a matter of judgment. The basic design is intended to separate the logic of what should happen, how it happens and the presentation. The View interacts with the user but passes that interaction on to the Controller to determine what should happen and to make it happen. Together the View and the Controller constitute the user interface of the application. The Model simply responds to the Controller or the view by either storing or retrieving some data. The MVC pattern also allows the View and the Model to talk directly to each other. The aim in the MVC approach is to try and decouple the concerns of each of the components as much as possible. In principle it should be possible to substitute a different View or Model and everything should still work as before. Joomla's approachIn Joomla things are set up so that there can be multiple possible views and controllers each used according to the URL specified. In addition there are also two additional components in the design. The first is an entry component which creates the controller and sets everything into action. There is also a template component which provides a division of the traditional View component into data format and presenation. In Joomla the View object is responsible for manipulating the data provided by the Model into a format that can be displayed by the template object. For example, raw data coming from a database is processed by the View into a form that is suitable for inclusion into an HTML or PDF document, say, and then this is finally laid out using a template which determines what fonts are used, colours and exact layout. In simple cases there is very little for the View to actually do, making it look as if the template object is doing all of the work of the View. The Joomla MVC classesThe Joomla framework provides base classes for each of the three MVC components: JController, JModel and JView. When you create a new Joomla MVC application it saves a great deal of time and effort to base your MVC classes on these. <ASIN:1847198147> <ASIN:1596714654@ALL> <ASIN:0982153716> <ASIN:1847194885> |
||||||
Last Updated ( Wednesday, 03 March 2010 ) |