We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Routing, very first request (front-controller)

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



51.2k

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
}


28.2k

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
}


51.2k
Accepted
answer

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