Case insensitivity for controller URI segments |
[eluser]Phil Sturgeon[/eluser]
At work I needed a way to allow controller names to be called up insensitive of case. I found a way to do it but it seems a little over the top. Either add this one-liner to systems/libraries/Router.php at the start of _validate_request()... Code: $segments[0] = strtolower($segments[0]); ... or create application/libraries/MY_Router.php and put the code below in the new file. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I believe a config option for this should be added, as while it may not be handy for everyone there are certain circumstances in which this could be useful.
[eluser]Phil Sturgeon[/eluser]
Mine would 404 if i tried to access http://example.com/controllername via http://example.com/ControllerName
[eluser]TheFuzzy0ne[/eluser]
That's one of the main the differences between Winblows and Linux file systems.
[eluser]Phil Sturgeon[/eluser]
This is on a virtualised Solaris installation running over a corporate network with Samba. I wonder which filesystem wins out.
[eluser]xwero[/eluser]
another one liner hack would be in the index.php Code: $_SERVER['PATH_INFO'] = strtolower($_SERVER['PATH_INFO']);
[eluser]TheFuzzy0ne[/eluser]
But that's so simple it's borderline insanity. I like it.
[eluser]Phil Sturgeon[/eluser]
That is simple, and it is also insane... not in the good way. That will lower-case EVERYTHING, including any data sent to the controller or any identifiers used to retrieve the data. It will also break any methods in controllers that use upper case! I will stick with my solution, it does the job. :-)
[eluser]TheFuzzy0ne[/eluser]
The only issue is if you require anything within your URL to be case sensitive. Since PHP is not case sensitive by nature, it shouldn't affect the calling of any methods.
[eluser]xwero[/eluser]
If you only want the first segment Code: list(,$first) = explode('/',$_SERVER['PATH_INFO']); |
Welcome Guest, Not a member yet? Register Sign In |