Skip to content
jkeesh edited this page Dec 27, 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("assn", $assignment); // assigns a variable to be used in the template $this->smarty->display('assignment.html'); // displays a template

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

In index.php you will also notice a method called basic_setup. This method is responsible for setting up all of the information that is needed throughout almost the whole site. This includes the course, the current quarter, the settings, and the role for the user in the current class. All normal paperless urls start like:

..../<quarter_id>/<class_name>/....

And this tuple of info allows you to find the Course object.

Clone this wiki locally