I'm looking for a one line route to route dashed controller and method names to the actual underscored controller and method names.
For example the URL
would route to
see: http://codeigniter.com/forums/viewreply/696690/ which gave me the idea to ask :)
That is exactly my requirement too and I was using routes like
In my previous project I needed to create 300-400 routing rules, most of them are due to dash to underscore conversion.
For my next project I eagerly want to avoid it. I have done some quick hack and tested it, though have not used in any live server, its working for me. Do the following..
Make sure the subclass_prefix is as follows in your system/application/config/config.php
Then upload a file named MY_Router.php in system/application/libraries directory.
Now you can freely use url like http://example.com/logued/presse-access and it will call the proper controller and function by automatically converting dash to underscore.
Edit: Here is our Codeigniter 2 solution which overrides the new CI_Router functions:
Now one has to place this file like application/core/MY_Router.php and make sure he has subclass_prefix is defined as
$config['subclass_prefix'] = 'MY_';in application/config/config.php
Few extra lines of code has been added in method
It is used so that one can make use of multi-level subdirectory inside controllers directory, whereas normally we can use single level subdirectory inside controllers folder and can call it in url. One can remove this code if it not necessary but it has no harm on the normal flow.