title: Echo executed twice
body: <p>I've added an ACL to my website but when I test the result of my role variable in the SecurityPlugin.php file I get the result twice.</p>
  
  <p>Why does Phalcon show the var_dump of $role twice? I'm fairly new to this framework and my initial thought was it might me due to routing in Phalcon?</p>
  
  <p>Phalcon version: 3.0.3</p>
  
  <p><strong>\app\plugins\SecurityPlugin.php</strong>
      
  
  <pre><code>use Phalcon\Acl;
  use Phalcon\Acl\Role;
  use Phalcon\Acl\Adapter\Memory as AclList;
  use Phalcon\Acl\Resource;
  use Phalcon\Events\Event;
  use Phalcon\Mvc\User\Plugin;
  use Phalcon\Mvc\Dispatcher;
  
  class SecurityPlugin extends Plugin
  
  {
  
  /**
   * Returns an existing or new access control list
   *
   * @returns AclList
   */
  public function getAcl()
  {
      if (!isset($this-&gt;persistent-&gt;acl)) {
          $acl = new AclList();
          $acl-&gt;setDefaultAction(Acl::DENY);
  
          // Register roles
          $roles = [
      'admins' =&gt; new Role(
        'admins',
        'Website administrators'
      ),
              'users'  =&gt; new Role(
                  'users',
                  'Member privileges, granted after sign in.'
              ),
              'guests' =&gt; new Role(
                  'guests',
                  'Anyone browsing the site who is not signed in is considered to be a "Guest".'
              )
          ];
          foreach ($roles as $role) {
              $acl-&gt;addRole($role);
          }
  
          //Private area resources
          $privateResources = array(
              'account'    =&gt; array('*')
          );
  
    $privateResourcesAdmin = array(
              'admin'     =&gt; array('*')
          );
  
    //Public area resources
          $publicResources = array(
              'index'       =&gt; array('*'),
              'register'    =&gt; array('*'),
              'errors'      =&gt; array('show401', 'show404', 'show500'),
              'register'    =&gt; array('*'),
              'login'       =&gt; array('*'),
              'logout'            =&gt; array('*')
          );
  
          foreach ($privateResources as $resource =&gt; $actions) {
              $acl-&gt;addResource(new Resource($resource), $actions);
          }
  
    foreach ($privateResourcesAdmin as $resource =&gt; $actions) {
      $acl-&gt;addResource(new Resource($resource), $actions);
    }
  
          foreach ($publicResources as $resource =&gt; $actions) {
              $acl-&gt;addResource(new Resource($resource), $actions);
          }
  
          //Grant access to public areas to users, admins and guests
          foreach ($roles as $role) {
              foreach ($publicResources as $resource =&gt; $actions) {
                  foreach ($actions as $action){
                      $acl-&gt;allow($role-&gt;getName(), $resource, $action);
                  }
              }
          }
  
          //Grant access to private area to role Users
          foreach ($privateResources as $resource =&gt; $actions) {
              foreach ($actions as $action){
                  $acl-&gt;allow('users', $resource, $action);
              }
          }
  
    foreach ($privateResourcesAdmin as $resource =&gt; $actions) {
              foreach ($actions as $action){
                  $acl-&gt;allow('admins', $resource, $action);
              }
          }
  
          //The acl is stored in session, APC would be useful here too
          $this-&gt;persistent-&gt;acl = $acl;
      }
      return $this-&gt;persistent-&gt;acl;
  }
  /**
   * This action is executed before execute any action in the application
   *
   * @param Event $event
   * @param Dispatcher $dispatcher
   * @return bool
   */
  public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher){
      $auth = $this-&gt;session-&gt;get('auth');
  
      if (!$auth){
          $role = 'guests';
      } else {
    if ($this-&gt;session-&gt;has("account_type")) {
        $type = $this-&gt;session-&gt;get("account_type");
        if($type == 99){
          $role = 'admins';
        } else {
          $role = 'users';
        }
    }
      }
  
      var_dump($role);
  
      $controller = $dispatcher-&gt;getControllerName();
      $action = $dispatcher-&gt;getActionName();
      $acl = $this-&gt;getAcl();
  
      if (!$acl-&gt;isResource($controller)) {
          $dispatcher-&gt;forward([
              'controller' =&gt; 'errors',
              'action'     =&gt; 'show404'
          ]);
          return false;
      }
  
      $allowed = $acl-&gt;isAllowed($role, $controller, $action);
  
      if (!$allowed) {
          $dispatcher-&gt;forward(array(
              'controller' =&gt; 'errors',
              'action'     =&gt; 'show401'
          ));
    $this-&gt;session-&gt;destroy();
          return false;
      }
  }
  }
  </code></pre>
  
  <p><strong>\public\index.php</strong></p>
  
  <pre><code>&lt;?php
  use Phalcon\Di\FactoryDefault;
  use Phalcon\Mvc\Dispatcher; //Used for ACL list and authorization routing
  use Phalcon\Events\Manager as EventsManager; //Used for ACL List
  use Phalcon\Mvc\Router; //Used for routing logout page
  
  error_reporting(E_ALL);
  
  define('BASE_PATH', dirname(__DIR__));
  define('APP_PATH', BASE_PATH . '/app');
  
  try {
  
      /**
       * The FactoryDefault Dependency Injector automatically registers
       * the services that provide a full stack framework.
       */
      $di = new FactoryDefault();
  
      /**
       * Read services
       */
      include APP_PATH . "/config/services.php";
  
      /**
       * Get config service for use in inline setup below
       */
      $config = $di-&gt;getConfig();
  
      /**
       * Include Autoloader
       */
      include APP_PATH . '/config/loader.php';
  
      //This makes sure the routes are correctly handled for authorized/unauthorized in people
      /**
       * MVC dispatcher
       */
      $di-&gt;set("dispatcher", function () use ($di) {
        // Create an events manager
         $eventsManager = $di-&gt;getShared('eventsManager');
  
         /**
         *Check if the user is allowed to access certain action using the SecurityPlugin
         *Listen for events produced in the dispatcher using the Security plugin
         */
         $eventsManager-&gt;attach(
             "dispatch:beforeExecuteRoute",
             new SecurityPlugin()
         );
  
        // Handle exceptions and not-found exceptions using NotFoundPlugin
         $eventsManager-&gt;attach(
             "dispatch:beforeException",
             new NotFoundPlugin()
         );
  
         $dispatcher = new Dispatcher();
  
         // Assign the events manager to the dispatcher
         $dispatcher-&gt;setEventsManager($eventsManager);
  
         return $dispatcher;
        }
      );
  
      /**
       * Handle and deploy the application
       */
      $application = new \Phalcon\Mvc\Application($di);
  
      echo $application-&gt;handle()-&gt;getContent();
  
  
  
  } catch (\Exception $e) {
      echo $e-&gt;getMessage() . '&lt;br&gt;';
      echo '&lt;pre&gt;' . $e-&gt;getTraceAsString() . '&lt;/pre&gt;';
  }
  </code></pre>