Welcome Guest, Not a member yet? Register   Sign In
Option to translate uri to camel case
#1

(This post was last modified: 04-29-2025, 10:46 AM by massimiliano1.mancini.)

Hi All,
I'm currently using improved auto-routing, so the option to convert URIs to camelCase caught my attention. It was introduced in version 4.5.0 and enabled by default starting from version 4.6.0. I had to disable it to avoid breaking my project's code, but I'm seriously considering refactoring the code to make use of it.
The documentation notes that "The option to disable 'Translate URI To CamelCase' exists only for backward compatibility. We don’t recommend to disable it." — but the reasons behind this recommendation aren't entirely clear to me.
Before diving headfirst into the refactor, I'd like to hear your thoughts on the pros and cons of enabling this option.
Thanks in advance for any suggestions, advice, and opinions!
Reply
#2

The only problem I can see would be server that expect all lowercase filenames like Linux.

Internally you should be alright.

I did a google search on CodeIgniter 4 Translate URI To CamelCase.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Linux doesn't require filenames or folders to be lowercase - it's just that the filesystem is case-sensitive. That means TestController.php and testcontroller.php are treated as different files.

Yes, this can cause problems, especially when class names, file names, and URI segments don't match exactly in case. That's why we recommend sticking with the default CodeIgniter 4 routing settings for consistency and reliability.

When using $translateUriToCamelCase = true:

    A URL like "test-controller" maps to the class "TestController"

When it's set to false:

    "testcontroller" maps to "Testcontroller"

And if you also enable $translateURIDashes = true:

    "test-controller" becomes "Test_controller"

We prefer using the default settings ($translateUriToCamelCase = true and $translateURIDashes = false) because they’re the most intuitive and align with CodeIgniter 4 coding style and autoloading conventions.
Reply
#4

Thanks a lot for the detailed answer, @michalsn. I think I'll go ahead and do the needed refactoring to enable the option and stick to CodeIgniter's routing guidelines. Any other input is more than welcome!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB