2.1 Creating a new controller class
# cd /var/www/e_test/application/front # cp front.php new_class.php
Now edit your new class file and give it the class name 'new_class'. Navigate to http://localhost/e_test/public_html/front/new_class. You will get an error saying that the template file new_class.tpl cannot be found. Edit new_class.php and add this line to the default event method:
$this->setTemplate('front.tpl');
Now you can go to 'http://localhost/e_test/public_html/front/new_class' and see the same page as you would get from loading the default controller class (front).
If you prefer Empathy can look for template files based on the current module name instead of the expected class name when a template hasn't been explicitly named. This can be toggled using the 'TPL_BY_CLASS' setting in config.yml.
2.2 Creating a new module
# cd /var/www/e_test/application # cp -r front new_module # mv new_module/front.php new_module/new_module.php
Edit the new_module class (the default controller for the new module) so that the class name is consistent with the class name as before, then make sure a default template file (new_module.tpl) is available for it under /var/www/e_test/presentation.
2.3 CustomController.php
The CustomController class resides in the top level application directory and is used to specify functionaliy that is available to any controller or should be executed on each request to the application. This can be useful for controlling access to modules based on user authorisation. For example you might have code that looks like this within the constructor:
if($this->module == "admin")
{
$u = new User($this); // using an Empathy storage object
if((!(isset($_SESSION['user_id']))) || (!($u->getAuth($_SESSION['user_id']))))
{
$this->redirect('login');
}
}