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

Dispatcher has detected a cyclic routing causing stability problems

Following code is causing error:

Dispatcher has detected a cyclic routing causing stability problems

    public function beforeDispatch(Event $event, Dispatcher $dispatcher)
    {

        $auth = $this->session->get('auth');
        if (!$auth){
            $role = 'Guest';
        } else {
            $role = $auth['role'];
        }

        $controller = strtolower($dispatcher->getControllerName());
        $action = strtolower($dispatcher->getActionName());

        $acl = $this->getAcl();
        if (!$acl->isResource($controller)) {
            $dispatcher->forward([
                'controller' => 'errors',
                'action'     => 'show404'
            ]);

            return false;
        }

        $allowed = $acl->isAllowed($role, $controller, $action);
        if (!$allowed) {
            $dispatcher->forward(array(
                'controller' => 'errors',
                'action'     => 'show401'
            ));
            return false;
        }
    }


77.7k
Accepted
answer
edited Aug '19

Have you allowed everyone to view the errors controller in the ACL?

Or you could skip the checks if the controller is the errors:

public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
    $controller = strtolower($dispatcher->getControllerName());
    if($controller == 'errors') {
        return true;
    }
    // the rest of your code...
}

But I'd add it to the ACL, unless you want to optimize performance.

Thanks,

Everything works fine after allowing access to all for errors in Acl.

Have you allowed everyone to view the errors controller in the ACL?

Or you could skip the checks if the controller is the errors:

public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
   $controller = strtolower($dispatcher->getControllerName());
  if($controller == 'errors') {
      return true;
  }
  // the rest of your code...
}

But I'd add it to the ACL, unless you want to optimize performance.