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.


Hello, I have basic security plugin but i cant start him. Where Im wrong ?!

use Phalcon\Mvc\User\Plugin;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
class Security extends Plugin
    public function beforeDispatch(Event $event, Dispatcher $dispatcher)
        if ($dispatcher->getControllerName() != 'index' && empty($this->session->get('auth'))) {
            return $this->response->redirect(\Modules\Admin\Models\Enom\IndexEnom::INDEX_URL);



Have you registered your plugin in the dispatcher of your application?


$di->set('dispatcher', function() use ($di) {

    //Obtain the standard eventsManager from the DI
    $eventsManager = $di->getShared('eventsManager');

    //Instantiate the Security plugin
    $security = new Security($di);

    //Listen for events produced in the dispatcher using the Security plugin
    $eventsManager->attach('dispatch', $security);

    $dispatcher = new Phalcon\Mvc\Dispatcher();

    //Bind the EventsManager to the Dispatcher

    return $dispatcher;

Check this: