Skip to content
brysonian edited this page Sep 13, 2010 · 5 revisions

Saint PHP Framework

Overview

Saint is a PHP web-application framework for quickly developing database-backed web applications using the model-view-controller design pattern. Using Saint it is possible to create sophisticated web applications with a minimum of developer overhead and a maximum of flexibility.

Saint is heavily inspired by the methodologies found in the ruby on rails framework. As such, a good resource at this time is any one of the numerous tutorials about ruby on rails. The basics of the framework consist of a single front controller which handles the forwarding of requests to the appropriate controller classes by using a url mapping.

Application Layout

A basic Saint application consists of a number of directories typically stored in the level above the live web directory:

app
controllers
helpers
models
views
config
db
lib
plugins
public

The MVC elements are organized in the app directory, and all configuration files are in config.
h2. Configuration

Saint requires a very minimal amount of configuration. database.php contains the parameters for accessing the database and urls.php contains the url mappings used by the front-controller.

Request Flow

The front controller (dispatch.php) intercepts requests and determines the correct controller class and action. The standard url mapping is: /controller/action/parameters. These mappings can be further modified in the config/urls.php file. Once the controller is found and loaded, the correct action method on the controller is executed. The controller methods hold the core lookups for a given “page”. When the action has finished execution, the correct view class is instantiated and interpreted then sent to the browser. View templates are located in the app/views directory. There are a few different template formats available. All views should be in a directory with the same name as the controller, in a file with the same name as the action, and end with a valid template extension. the .phtml extension will treat the contents as valid in-line php. the .pxml extension will let you output xml served with the correct mime type. Finally the .xsl causes the framework to treat the controller variables as XML and perform a XSLT operation to produce the HTML.


Any instance variables on the controller class are made available to the phtml and pxml views as local variables. For instance if you set $this→foo = “bar” in an action method, this variable will be available in the template as $foo.

File Locations

As is apparent from the application layout, the bulk of code for a site is located in the ”app” directory. All controllers are located in the “controllers” directory. These controllers are primarily responsible for handling the incoming request, loading data from the database (using the model objects from models) and setting variables used by the views. Each method on the controller corresponds to an action from the url. Methods which are accessible as actions are prefixed with an underscore character. For example the index action for a controller (executed automatically which only a controller name, but not an action, is specified) is named _index.

All view templates are located in the “views” directory, which contains a sub-directory for each controller. Inside these sub-directories are template files for each action. For instance, the template for the index action of the home controller is located at /app/views/home/index.phtml

Clone this wiki locally