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

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):
        // 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): var_dump(class_exists("InspiremeController")); --> bool(true)

$c = new InspiremeController(); var_dump(method_exists($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?



98.9k

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

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


22.6k

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 =(



98.9k

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: https://docs.phalcon.io/en/latest/reference/routing.html#testing-your-routes or set some not-found defaults: https://docs.phalcon.io/en/latest/reference/routing.html#not-found-paths



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



98.9k

Great, the problem starting to look weird :)



22.6k

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?