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.

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:)



31.3k
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!