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

phalcon cannot find CamelCase named Controller?

i have a contoller named "DataProjectController.php",then ervey time i access the URL "/DataProject", it response "DataprojectooController handler class cannot be loaded", but if I rename it to "DataprojectController.php", it works. --- it seams that phalcon cannot use CamelCase named Controller.

help!

edited Apr '15

if your controller is 'DataProjectController' phalcon will do uncamelize and your url will be 'data-project' or 'data_project'. Both works.

Go with the first since looks nicer and make sure the view folder name is also 'data-project' or phalcon won't be able to find it.

https://docs.phalcon.io/en/latest/reference/routing.html - search for camelized

It's very frustrating thing in Phalcon and I spent many hours to debug it. I have StaticPageController and route [controller => 'staticPage'] . Phalcon can autoload it on Windows machine, but not on Linux. But problem is not in case-insensitive paths in Windows but in Phalcon itself - because it transforms StaticPageController to StaticpageController - i.e. loses one camelcase letter in the middle of word! https://github.com/phalcon/cphalcon/issues/2572#issuecomment-64060943

So even if route is hardcoded with camelcase (not obtained from the client as above) it will not work. Even in hardcoded routes we will write 'static-page' as controller name to load StaticPageController.

Controller names are camelized, this means that characters (-) and (_) are removed and the next character is uppercased. For instance, some_controller is converted to SomeController.

This is the way Phalcon handles camelcase and is documented since version 1.x. I don't see a problem here while it is documented and works as documented. I understand that must be frustrating for people who develop on windows and then the application doesn't work on linux, but is a 2 years old issue and from what I understand the phalcon team decided that is not a bug and it works as indended.

I specially mentioned that it works on Windows and not works on Linux to point that it's not about file systems. It may not work but works on Windows due to Windows not differs case in filenames. Underscore and dash camilization means that underscores and dashes removes and letters after it are camelized. It works as expected. But word parts that ALREADY was camelized will not loose camelization. But Phalcon looses it.



4.2k

Still a "problem" today, that already camelized controller names are converted to lowercase