RPL MVC

From Rhypedigital

Revision as of 09:50, 21 June 2010 by WikiSysop (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Model-View-Controller Architecture

The Model-View-Controller architecture is an application design architecture which tries to separate business logic from user input and data presentation.

The model encapsulates data storage. Generally (but not necessarily) data is stored in an SQL database; the model is in effect a set of APIs to the database. The model often includes an Active Record interface directly to the database tables, but might also include APIs which encapsulate higher-level functions (eg., transfer a specified amount of money from customer A to customer B).

Views are used to control the presentation of data to the user, which in the case of web applications is typically the generation of HTML pages. A view will be usually be passed one or more model objects which will be used to provide the data to be presented. In RiPHPLib, the views will use skeleton files which contain a mixture of raw HTML, substitution markers which are replaced by data values, and limited control logic. These files do not contain PHP code.

Controllers receive input from the user (in the case of web application, CGI parameters and cookies), use model objects to manipulate data, and then (again in the case of web applications) use a view to generate the HTML page.

This is different to what might be considered a "standard" PHP program, when these elements are combined. It makes it possible, for instance, to change the layout of the generated HTML pages (over and above CSS changes) by editing the skeleton files without interfering with the logic of the application. It makes it possible to alter the underlying data storage by editing the model objects; if the API is unchanged then the application will continue to behave in the same way.

Personal tools