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

Why i see cyclic routing?

Hi guys!

I creating auth technology.

<?php

class AdminController extends \Phalcon\Mvc\Controller
{

    public function initialize()
    {

        if($this->session->get('auth')) {

            return $this->dispatcher->forward(array(
                'controller' => 'admin',
                'action' => 'index'
            ));

        } else {

            return $this->dispatcher->forward(array(
                'controller' => 'admin',
                'action' => 'login'
            ));

        }

    }
    public function indexAction()
    {
        $this->view->hello = 'Hello, ' . ADMIN_USERNAME; 
    }

    public function loginAction()
    {
        if($this->request->isPost()) {

            $username = $this->request->getPost('username');
            $password = $this->request->getPost('password');

            if($username == ADMIN_USERNAME && $password == ADMIN_PASSWORD) {
                $this->session->set('auth', true);

                return $this->dispatcher->forward(array(
                    'controller' => 'admin',
                    'action' => 'index'
                ));
            }
        }
    }

}

and routing:

$router->add("/admin/:action/", array(
    'controller' => 'admin',
    'action' => 1
));

but phalcon returned "PhalconException: Dispatcher has detected a cyclic routing causing stability problems"

what am I doing wrong?

Sorry for my english:)



43.9k
Accepted
answer

hi,

I think it is because you check the auth session in initialize() method. Put that checking in the indexAction()

edited Aug '15

yes yes, i understand my error. thanks for a question le51!