CodeIgniter URI routing issue with controller folders
How To, PHP December 8th, 2011
I’ve seen a lot of people requesting help on figuring out routing issues on CodeIgniter (2.1.0 as of this entry).
A few of them have problems creating a route to a controller folder structure (/application/controllers/folder/controller), but really it is the same as creating a custom route to a non ‘folder’ed’ controller, you just have to define the variable in the routing path.
Here is our scenario, I have a URL of http://example.com/account/manage/4123245/jakub
So if we analyze our URI, we have:
account – folder
manage – controller (with only an index class)
4123245 – a numeric value (input)
jakub – a string slug value (just extra input)
From that we need to make sure that codeigniter understands our URI (and it will not by default!).
so we edit our /application/config/routes.php
$route['account/manage/(:num)/(:any)'] = "account/manage/index/$1/$2";
Index is the key here, as we need to route to the class (which is the index), the values $1, $2 are just input (1st, 2nd respectively) to show it goes to the index class.
There you have it, no more route issues with folders in your controller structure.
Happy Code Igniting!
- kelvin
- Info
- Jakub
- Jakub
- Peter Nemeth
- Jakub
- Peter Nemeth
- Hawk
- Jakub
Welcome to