Dispatcher has detected a cyclic routing causing stability problems - Sub Directory Controller Routing problem

I have this error:

Dispatcher has detected a cyclic routing causing stability problems

  • 0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('Dispatcher has ...', 1)
  • 1 [internal function]: Phalcon\Dispatcher->_dispatch()
  • 2 [internal function]: Phalcon\Dispatcher->dispatch()
  • 3 C:\xampp\htdocs\phalcon-test\public\index.php(121): Phalcon\Mvc\Application->handle()
  • 4 {main}

So this is what I am trying to do, I would like to create a sub controller under a sub directory. Here's the arrangement of my controllers folder:

controllers

------- Module-one (folder)

            ------------------ ProductsController.php

ControllerBase.php


On the loader.php I have this code :

$loader->registerDirs( [ $config->application->controllersDir, $config->application->modelsDir ] )->register();

$loader->registerNamespaces(array( // Main 'Controllers' =>'app/controllers/', 'Models' =>'app/models/', // Admin Routing 'Controllers\Module-one'=>'app/controllers/module-one'

))->register();


And for me to call it via Routes, here's my code in my routes.php

$router->add("/module-one", array( 'namespace' => 'Controllers\Module-one', 'controller' => 'products', 'action' => 'index', ));


I am not sure why I am having that error (above)

I just want to put my controller on a sub directory which is being called via routes so that I can arrange the files of the system i'm working on

That happens when I try to visit the url : http://localhost/phalcon-test/module-one

(phalcon-test is the project directory in my htdocs)

Thank you for your help!

Sub directory doesn't have anythig to do here. Do you have dispatcher defined in di ? Can you show it here ?

Thank you for your reply. Yes, however it is just for the 404. Here's the code:

$di->set( 'dispatcher', function() use ($di) {

                    $evManager = $di->getShared('eventsManager');

                    $evManager->attach(
                        "dispatch:beforeException",
                        function($event, $dispatcher, $exception)
                        {
                            switch ($exception->getCode()) {
                                case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                                case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
                                    $dispatcher->forward(
                                        array(
                                            'controller' => 'error',
                                            'action'     => 'show404',
                                        )
                                    );
                                    return false;
                            }
                        }
                    );
                    $dispatcher = new PhDispatcher();
                    $dispatcher->setEventsManager($evManager);
                    return $dispatcher;
                },
                true
            );

Try remove this event listener and check if it works without it.

Thank you again for your reply.

I removed the dispatcher from my previous comment and got this error message instead:

ProductsController handler class cannot be loaded

  • 0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('ProductsControl...', 2)
  • 1 [internal function]: Phalcon\Dispatcher->_dispatch()
  • 2 [internal function]: Phalcon\Dispatcher->dispatch()
  • 3 C:\xampp\htdocs\phalcon-test\public\index.php(121): Phalcon\Mvc\Application->handle()
  • 4 {main}
edited Sep '16

Try

 'Controllers\Module-one'=>'app/controllers/module-one/'

Perhaps dash is problem.

Thank you and sorry for the later reply.

I have the same problem.

Maybe I should just ask if how can I put the controllers inside folders to organized it better?

But you alreday did it. Where is your loader.php loaded ? Did you tried without dash ?

Yes I did. Do you want me to send my codes instead? What are the files you need?

edited Sep '16

Just post whole loader.php and file where loader.php is included.

Also you can post your ProductsController.php content

Hello, Wojciech Ślawski, what's the update on this one what do you think?

Above link don't works. :) Post link in backticks.