Dummy - The framework for Dummies - Controller

The basic idea behind Dummy Framework is that the framework should call your own .php file to handle the page after the basic framework home-keeping is done.

However, you might want to tweak some of the activities inside the framework before or after your .php (henceforth called your Controller) executes. To allow the framework to have access to those moments, you should create a master.php in your /site/ folder, and create a DefaultDummyController instance. You can pretty much copy the DefaultDummyController class from DummySettings.php and only rename the header to:

class DummyController extends DefaultDummyController {

There are 4 functions inside this class that should be pretty self-explanatory:

onStart(&$Dummy) - is triggered as soon as the script is ready to work. All constants and settings have been set and you can now change the $Dummy settings as you please, as well define routes. You could also implement authentication in here if you wanted.

onConnect(&$Dummy) - if using a database, this will be triggered after the database is connected (note it uses delayed connect - the database is only really connected if it is used). This is a good place to run early scripts that require the database.

onLoadView(&$Dummy) - triggered after your template (View) is loaded and ready to use. This is mostly for common activities like envelope the template inside a frame (html > body) or any other activities in the template that happens all the time.

onTerminate (&$Dummy) - triggered just before the main $Dummy->terminate is invoked. You can do final template activities, set up meta tags or hreflangs or anything you need your Controller to do for the page being served to be finished.

As well as instantiating DefaultDummyController in your master.php, this is a good place to define "global" functions. Since this file is invoked on the same context (namespace) as your Controller will be called, functions defined here will be accessible to them.

The actual Controller for your page (/site/Controllers/[name_of_the_page].php) is called near the end of the workflow (see complete workflow here): just before the $Dummy->dc->onTerminate (your DefaultDummyController onTerminate) and $Dummy->terminate. That is because most of the features of $Dummy are on preparing everything for your code, so it is only logical your code is last. 

Your Controller have access to all functions and variables from $Dummy by using either $Dummy or $this. See the complete list of those here.

You will most likely handle mostly two objects: the $Dummy->view (the template, check here all the functions of the View) and $Dummy->db (the database, check here all the functions of the CDBO) as well setting Dummy variables that control the framework.

◀ Back

Ads by google (click here to hide, consider tipping me to maintain the site)
Check other of my articles, like: What changed in the world since you were born?