Gallery3:Developer Handbook:MVC - Gallery Codex
Personal tools

Gallery3:Developer Handbook:MVC

From Gallery Codex

Models, Views and Controllers

Gallery 3 uses a common architecture called Model / View / Controller (MVC). This is a simple division of labor between different parts of the code that makes it easier to separate out concepts. There is extensive documentation about this concept on Wikipedia.

Models contain data and make sure that it’s sane. An Item_Model contains all data about an individual album, photo or movie, while the User_Model contains all data about an individual user. Each model typically maps to a row in the database and the model code is responsible for ensuring data integrity. For more information including detailed examples, refer to Kohana’s documentation on Models.

Controllers are the essential application. They interpret requests from the user, then use all the other building blocks available in the framework to take the appropriate action and return the correct response. Controllers typically process requests from a web browser, load up one or more models and then delegate to a View to render an HTML response back to the web browser. A controller’s responsibility can be as simple as printing out an HTML response, or as complex as supporting uploading a photo or creating a new album. Because Controllers are typically associated with a type of output, they shouldn’t contain much complexity. Instead, they should delegate the hard work to helpers and libraries. For more information including detailed examples, refer to Kohana’s documentation on Controllers.

Views contain the browser specific display information for your application. Typically this is HTML output. In Gallery 3, a view is a PHP file which is predominantly data, but has embedded PHP code to render relevant data. Controllers load up data and make it available to the view which then renders the output. For more information including detailed examples, refer to Kohana’s documentation on Views.