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.

Controller unexplainably ignored. How to troubleshoot?

Yo. I have a few controllers, they work as expected, but now when I added a new one, it is ignored by the framework, and the last two hours of troubleshooting have been unrewarding. I can't find anything wrong. What happens is that the IndexController::indexAction() is loaded.

  • The controller is named "InspiremeController" (I'd like to call it "InspireMeController", but I'm unsure how to handle camel case in routing, please advise here as well).
  • I've added this route (if I change the controller / action to other ones I run, it works): ```php // Add route to inspire-me page. $router->add( "/inspire-me", array( "controller" => "inspireme", "action" => "test" ) ); ```
  • I've ensured that the controller / action can be found like this (in index.php, before instantiating the router): vardump(classexists("InspiremeController")); --> bool(true)

$c = new InspiremeController(); vardump(methodexists($c, "testAction")); --> bool(true)

The InspiremeController currently holds indexAction and testAction (to try names), and both just try to die. Still, the IndexController::indexAction() is loaded and processed.

Why doesn't it work?

Best regards, dimhoLt

Update: it doesn't matter what I name the controller. All new controllers are ignored, even though they're correctly named and placed in the source. I've restarted the servers and everything. I've tried to add on both my work stations with exactly the same result, both run Mac OSX.

How can I troubleshoot?



81.8k

If you want to use InspireMeController you need to define the route as follows:

$router->add("/inspire-me", array(
    "controller" => "inspire-me",
    "action"     => "test"
));


13.4k

Awesome. Thanks =)

The other thing though; my new controllers are ignored. How can I troubleshoot this? Find out what's wrong? I can't add them in routes or access their actions implicitly either. Is there a log I've be unsuccessful in confing or something? I notice that if I point it to an existing (working) controller and supply an invalid action, I get an error message, but any new controller added just renders IndexController::indexAction() no matter how I put it =(



81.8k

Maybe there is something wrong with how the routes are set in the router, normally if index/index is displayed this means the URI is not matched by any route set in the router, check this to play with routes and uris and test why a specific route is not matched: http://docs.phalconphp.com/en/latest/reference/routing.html#testing-your-routes or set some not-found defaults: http://docs.phalconphp.com/en/latest/reference/routing.html#not-found-paths



13.4k
Accepted
answer

I've been testing now, and it appears that the controller (including the CamelCase-one; as in your example) is matched. The route is also matched implicitly if I create "NewController" and access path "/new/index". However, no matter what I do, all controllers I add just display index/index action. Any more clues on how to troubleshoot?

Edit: I've found the problem, and it's obviously due to my still n00bness of Phalcon. I hadn't added it to the ACL and was therefore thrown out. Thanks again for your help and a totally awesome framework.



81.8k

Great, the problem starting to look weird :)



13.4k

Indeed it was =) I'm a bit unsure though about that other thing, regarding severl-word CamelCase controller names. I've added a controller layout, in this case named "inspire-me.volt" in the "views"-folder, but it's not included. Can I assume the syntax is lower-case with hyphens instead of camel case when referring to controller names?