Difference between revisions of "Model-View-Controller"

From Joomla! Documentation

m (→‎Component development series: update to section)
m (spelling)
(9 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===
+
===Component development series=== <!--T:3-->
{{Navbox
+
</translate>
|style  =  width:auto; margin:10px;
+
<div class="large-6 column">
|name      = Developing MVC
+
<translate>
|state      = off
+
====Developing a MVC Component for J3.x ==== <!--T:4-->
|navbar    = off
+
[[J3.2:Developing a MVC Component/Introduction|Introduction to Developing a 3.x MVC]]
|title      = Developing a MVC in {{JVer|2.5}}
+
</translate>
|titlestyle = font-weight:bold; font-size:1.10em;
 
|group1      = ''Articles in this series''
 
|list1    =
 
<div class="hlist">
 
*&nbsp;[[J2.5:Developing a MVC Component/Introduction|Introduction]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Developing a Basic Component|Developing a Basic Component]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding a view to the site part|Adding a view to the site part]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding a menu type to the site part|Adding a menu type to the site part]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding a model to the site part|Adding a model to the site part]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding a variable request in the menu type|Adding a variable request in the menu type]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Using the database|Using the database]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Basic backend|Basic backend]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding language management|Adding language management]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding backend actions|Adding backend actions]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding decorations to the backend|Adding decorations to the backend]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding verifications|Adding verifications]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding categories|Adding categories]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding configuration|Adding configuration]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding ACL|Adding ACL]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding an install-uninstall-update script file|Adding an install/uninstall/update script file]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Using the language filter facility|Using the language filter facility]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Adding an update server|Adding an update server]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Example of a frontend update function|Example of a Frontend Update Function]]
 
*&nbsp;[[J2.5:Developing a MVC Component/Example of menu parameters and stylesheets|Example of Menu Parameters & Stylesheets]]
 
 
</div>
 
</div>
|list1style  = background-color: cornsilk; padding:2px; font-size:1em; text-align:left; width:100%;
+
<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__

Revision as of 21:00, 24 February 2014

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

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[edit]

Component development series[edit]

Developing a MVC Component for J3.x[edit]

Introduction to Developing a 3.x MVC

Developing a MVC Component for J2.5[edit]

Introduction to Developing a 2.5 MVC