Difference between revisions of "Model-View-Controller"

From Joomla! Documentation

m
m (→‎Component development series: margins and auto width)
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{Chunk:Model-View-Controller}}
 
{{Chunk:Model-View-Controller}}
 +
 +
==See Also==
 +
* [[Understanding Output Overrides]]
 +
* [[Developers]]
 +
* [[JModel]]
 +
* [[JView]]
 +
* [[JController]]
 +
 +
===Component development series===
 +
{{Navbox
 +
|style  =  width:auto; margin:10px;
 +
|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%;
 +
}}
  
 
[[Category:Landing Pages]][[Category:Glossary]]
 
[[Category:Landing Pages]][[Category:Glossary]]

Revision as of 19:34, 11 September 2012

<translate> 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.

</translate>

See Also[edit]

Component development series[edit]