Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

methods that will always be executed

I need to insert some methods that will always be executed on the system, eg check if the system is active or maintenance (getting some data of database), check if the user was locked or not, among others. What would be the best place to put these methods?



1.8k
Accepted
answer

Put your logic in a class, and instantiate an instance of that class in your Dependency Injector (in app/services.php or wheverer). Then create a "BaseController" that acts upon your class in a 'beforeExecuteRoute' method, and extend your other controllers from you 'BaseController'. You should be all set.

E.g.:

class BaseController extends Phalcon\Mvc\Controller { public function beforeExecuteRoute(Dispatcher $dispatcher) { if($this->myClass->maintenanceModeActive()) { $dispatcher->forward(array( 'controller' => 'maintenance', 'action' => 'index', 'params' => array('forwarded' => 'true') )); return false; } } }