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.

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;
        }
    }


68.8k
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.