Matchbox with modular routes in CodeIgniter
Posted CodeIgniter at Jun 06, 2008
I have seen a few people posting around the CodeIgniter forums looking for a way to add config items and routes into Matchbox and after a two-minute ponder I realised it was ridiculously simple. To get it working on your CodeIgniter setup.- Open up 'application/libraries/Router.php'. This is the Matchbox replacement router library and not your core CodeIgniter one.
- Around line 126 add in the following:
// Load module routes files. $modules = array(); foreach ($this->_matchbox->directory_array() as $directory): foreach(glob(APPPATH.$directory.'/*', GLOB_ONLYDIR) as $module): @include_once($module.'/config/routes.php'); endforeach; endforeach;
- In each of your modules that you want to have routes, make a folder /config/ and make a new file routes.php.
- Put your routes in!
The routes work in exactly the same way, you are not required to do this for every module and it means you can put any module in or out of your installation without worrying about the main routes file.
For those of you who don't like hacking libraries like this, have no fear, I have mentioned this to Matchbox creator Zacharias Knudsen and it will be included in the next release.
Comments