Actions

Difference between revisions of "Model-View-Controller"

From Joomla! Documentation

m (update to list of articles in series box)
m (spelling)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Chunk:Model-View-Controller}}
+
<noinclude><languages/></noinclude>
 +
<translate>
 +
<!--T:1-->
 +
{{Chunk:Model-View-Controller/en}}
  
==See Also==
+
==See Also== <!--T:2-->
 
* [[Understanding Output Overrides]]
 
* [[Understanding Output Overrides]]
 
* [[Developers]]
 
* [[Developers]]
* [[JModel]]
+
* [http://api.joomla.org/11.4/Joomla-Platform/Application/JModel.html JModel]
* [[JView]]
+
* [http://api.joomla.org/11.4/Joomla-Platform/Application/JView.html JView]
* [[JController]]
+
* [http://api.joomla.org/11.4/Joomla-Platform/Application/JController.html JController]
 
+
===Component development series===
+
{{Navbox
+
|style  = float:left; width:100%;
+
|name      = Developing MVC
+
|state      = off
+
|navbar    = off
+
|title      = Developing a MVC in {{JVer|2.5}}
+
|titlestyle = font-weight:bold; font-size:1.10em;
+
|group1      = ''Articles in this series''
+
|list1    =
+
[[Developing a Model-View-Controller Component/2.5/Developing a Basic Component|Developing a Basic Component]]  •  [[Developing a Model-View-Controller Component/2.5/Adding a view to the site part|Adding a view to the site part]]  •  [[Developing a Model-View-Controller Component/2.5/Adding a menu type to the site part|Adding a menu type to the site part]]  •  [[Developing a Model-View-Controller Component/2.5/Adding a model to the site part|Adding a model to the site part]]  •  [[Developing a Model-View-Controller Component/2.5/Adding a variable request in the menu type|Adding a variable request in the menu type]]  •  [[Developing a Model-View-Controller Component/2.5/Using the database|Using the database]]  •  [[Developing a Model-View-Controller Component/2.5/Basic backend|Basic backend]]  •  [[Developing a Model-View-Controller Component/2.5/Adding language management|Adding language management]]  •  [[Developing a Model-View-Controller Component/2.5/Adding backend actions|Adding backend actions]]  •  [[Developing a Model-View-Controller Component/2.5/Adding decorations to the backend|Adding decorations to the backend]]  •  [[Developing a Model-View-Controller Component/2.5/Adding verifications|Adding verifications]]  •  [[Developing a Model-View-Controller Component/2.5/Adding categories|Adding categories]]  •  [[Developing a Model-View-Controller Component/2.5/Adding configuration|Adding configuration]]  •  [[Developing a Model-View-Controller Component/2.5/Adding ACL|Adding ACL]]  •  [[Developing a Model-View-Controller Component/2.5/Adding an install-uninstall-update script file|Adding an install/uninstall/update script file]]  •  [[Developing a Model-View-Controller Component/2.5/Using the language filter facility|Using the language filter facility]]  •  [[Developing a Model-View-Controller Component/2.5/Adding an update server|Adding an update server]]  •  [[Developing a Model-View-Controller Component/2.5/Example of a frontend update function|Example of a Frontend Update Function]]  •  [[Developing a Model-View-Controller Component/2.5/Example of menu parameters and stylesheets|Example of Menu Parameters & Stylesheets]]
+
|list1style  = background-color: cornsilk; padding:2px; font-size:1em; text-align:left; width:100%;
+
}}
+
 
+
  
 +
===Component development series=== <!--T:3-->
 +
</translate>
 +
<div class="large-6 column">
 +
<translate>
 +
====Developing a MVC Component for J3.x ==== <!--T:4-->
 +
[[J3.2:Developing a MVC Component/Introduction|Introduction to Developing a 3.x MVC]]
 +
</translate>
 +
</div>
 +
<div class="large-6 column">
 +
<translate>
 +
====Developing a MVC Component for J2.5 ==== <!--T:5-->
 +
[[J2.5:Developing a MVC Component/Introduction|Introduction to Developing a 2.5 MVC]]
 +
</translate>
 +
</div>
 +
<translate>
 +
<!--T:6-->
 
[[Category:Landing Pages]][[Category:Glossary]]
 
[[Category:Landing Pages]][[Category:Glossary]]
 +
</translate>__NOTOC__

Latest revision as of 21:00, 24 February 2014

Other languages: català 86% • ‎English 100% • ‎español 100% • ‎français 100% • ‎Bahasa Indonesia 100% • ‎日本語 100% • ‎Nederlands 100% • ‎Kiswahili 100%

Joomla makes extensive use of the Model-View-Controller design pattern.

When Joomla is started to process a request from a user, such as a GET for a particular page, or a POST containing form data, one of the first things that Joomla does is to analyse the URL to determine which component will be responsible for processing the request, and hand control over to that component.

If the component has been designed according to the MVC pattern, it will pass control to the controller. The controller is responsible for analysing the request and determining which model(s) will be needed to satisfy the request, and which view should be used to return the results back to the user.

The model encapsulates the data used by the component. In most cases this data will come from a database, either the Joomla database, or some external database, but it is also possible for the model to obtain data from other sources, such as via a web services API running on another server. The model is also responsible for updating the database where appropriate. The purpose of the model is to isolate the controller and view from the details of how data is obtained or amended.

The view is responsible for generating the output that gets sent to the browser by the component. It calls on the model for any information it needs and formats it appropriately. For example, a list of data items pulled from the model could be wrapped into an HTML table by the view.

Since Joomla is designed to be highly modular, the output from the component is generally only part of the complete web page that the user will ultimately see. Once the view has generated the output the component hands control back to the Joomla framework which then loads and executes the template. The template combines the output from the component, and any modules that are active on the current page, so that it can be delivered to the browser as a single page.

To provide additional power and flexibility to web designers, who may only be concerned with creating new designs rather than manipulating the underlying code, Joomla splits the traditional view into a separate view and layout. The view pulls data from the model, as in a traditional MVC pattern, but then simply makes that data available to the layout, which is responsible for formatting the data for presentation to the user. The advantage of having this split is that the Joomla template system provides a simple mechanism for layouts to be overridden in the template. These layout overrides (often called "template overrides" because they form part of the template, although actually it is the layout that is being overridden) are bundled with the template and give the template designer complete control over all the output from the Joomla core and any installed third-party extensions that comply with the MVC design pattern.



See Also

Component development series

Developing a MVC Component for J3.x

Introduction to Developing a 3.x MVC

Developing a MVC Component for J2.5

Introduction to Developing a 2.5 MVC