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?



32.7k

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
}


11.3k

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

One solution is to create a base controller:

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

Other controllers will extend the base one:

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

```



32.7k
Accepted
answer

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