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.

Routing, very first request (front-controller)

dear forumers, how to set a front-controller which executes everytime and before any/all request?



35.1k

One solution is to create a base controller:

class BaseController extends \Phalcon\Mvc\Controller
{
    public function beforeExecuteRoute()
    {
        // Do your stuff here
    }
}

Other controllers will extend the base one:

class UserController extends BaseController
{
    // .... your code
}


12.9k

thanks, but what if I have a mult module application?

One solution is to create a base controller:

class BaseController extends \Phalcon\Mvc\Controller
{
   public function beforeExecuteRoute()
   {
      // Do your stuff here
   }
}

Other controllers will extend the base one:

class UserController extends BaseController
{
  // .... your code
}


35.1k
Accepted
answer

Then you should overwrite the default behavior of dispatcher. See the docs: https://docs.phalconphp.com/en/latest/reference/dispatching.html