Skip to content
econner edited this page Sep 22, 2011 · 7 revisions

Code Structure

Paperless follows the Model-View-Controller architecture and makes use of two additional libraries: ToroPHP and the Smarty Template Engine. ToroPHP provides a simple URL routing mechanism and the Smarty template engine makes for easy separation of controllers from views. You might want to read a bit about each of these components before continuing.

All requests to a Paperless page first hit index.php where they are routed to a specific class specified by the URL requested. For example, in the following snippet,

$site = new ToroApplication(Array(
    Array('^\/([a-zA-Z0-9_ \-]+)\/student\/([a-zA-Z0-9_ \-]+)\/?$', 'regex', 'StudentHandler'),
));

a requested URL path that matches the regular expression above will be mapped by Toro to the StudentHandler class in controllers/student.php. Every controller is derived from the class ToroHandler defined in index.php. The ToroHandler class sets up the basic variables needed in each template and creates an objet $smarty that allows the controllers to pass variables to the views.

The controllers define and display templates like so, $this->smarty->assign("username", USERNAME); // assigns a variable to be used in the template $this->smarty->display('assignment.html'); // displays a template

All the templates can be found in ./templates/templates/ and Smarty automatically handles piecing these together with its template language

Clone this wiki locally