Goodbye Matchbox, Hello Modular Separation
I've been using Matchbox in one of its many forms for several years - almost as long as I have been using CodeIgniter - and it got to the point where I could not use CodeIgniter without it. After all this time I have finally found an alternative to handle my CodeIgniter applications modular structure.
Matchbox is a modular system written by Zacharias Knudsen - a very talented young developer who is sadly not as active as he used to be. Modular CodeIgniter basically means you can group your controllers, models and views for a specific section of the site together.
The new system I have been implementing to my applications is Modular Separation* by wiredesignz. Modular Separation is purely PHP 5 which gives it a slight edge over Matchbox from the get-go as it can leave out a lot of the extra PHP 4 support and go right for the much cleaner & quicker full OOP approach.
That said, dropping PHP 4 support by itself was not quite enough to make me want to drop Matchbox from my applications. Matchbox still had a few features over Modular Separation such as multiple module directories (PyroCMS has both /modules and /core_modules) which helps to separate out different types of modules. After some pestering and nagging, wiredesignz added that feature (and a few others) and made Modular Separation seem much more appealing to me.
One of those brilliant features - added in 1.9 - is 404 routing. I have worked on many applications that like to control how the 404 works. This could be for many reasons, be it sending the user to a controller that has a full design instead of the usual R.B.O.D 404 page, or it could be for more advanced systems that use some sort of page manager: E.g http://example.com/page-name.
$route['404'] = 'pages';
That route will send any 404 errors off the the pages module. More routing can be done from withing the module as Modular Separation supports another brilliant feature: modular routing.
Modular routing for CodeIgniter is nothing new - I wrote a simple patch to support modular routes in Matchbox a while back and the feature eventually made it into Matchbox 2. Zacharias and I both used a very similar approach, which was effectively adding extra routes into the main $routes array.
Modular Separation will match a result in the main config/routes.php file, then look at the module to see if any more routes match the routed URL. This means you can keep general rules in the global file, then module specific rules can be kept in the module itself. Keeping control of a modules routes to the specific module is brilliant and cuts down on the possibility of routes conflicting with each other too.
PyroCMS has now been converted to use Modular Separation and it has shaved a few 100ths of a second off here and there. That's good enough for me, especially as I now have fewer extended libraries in my applications/libraries folder.
I am not suggestion you drop Matchbox right now, I have no idea where is going and I may some day switch back. Right now however, I will be using Modular Separation and suggest you give it a try if you are starting a new project.
* Confusingly, Matchbox used to be called Modular Sepration a year or two back, so be careful when looking around the web for details. The forum thread to look for help on the new Modular Separation (PHP 5) by wiredesignz is this one.

Comments
Bjorn
2009-11-24
Cool. I've mostly used Matchbox since it comes bundled with BackendPro, which is the easiest way I've found so far to "kick-start" a website which needs users/registration/login/etc.
Devbeans
2009-12-02
Great job! I should say routing with this one is better than matchbox. Keep up the good work!
Gin
2009-12-03
About 404 page - i thought that for SEO much better when you not redirected to special 404 controller page, but when you get 404 headers on the same url that doesn't exist. I mean - there is no reasons to be redirected, just stay on the same page but show unique designed 404 page and return 404 headers. And as i know that is impossible with matchbox and i guess with modular separation as well. What do you think?
Phil Sturgeon
2009-12-03
@Gin: The 404 route does not redirect you anywhere, it is a way to load a certain module if nothing else is found. This keeps you on the same URL and wont do anything with headers unless you tell it to.
Even so, if you then use show_404() in the routed controller, the URL will still be whatever page you requested and 404 header will be returned as usual.
Eric
2009-12-30
I just pulled the latest from GitHub and it looks like you are still using Matchbox. Did you decide to stick with it?
Sid
2011-04-10
Phil,
I'm using the Modular Separation (HMVC) code by wiredesignz. It rocks! I've been reading through the code of your template library. Thanks for the contribution!
Steve
2011-07-15
Phil,
Like others, I was introduced to matchbox via BackendPro. We are not in the business of creating new sites on a regular basis. Instead we are adding to an existing site. Matchbox became a useful tool to set up common libraries and models along with a large number of website specific controllers and views.
So my question to you is around the amount of effort it took to move from MatchBox to Modular Separation. We would also be looking at a need to port the areas of BackendPro that we use.
Thanks in advance for your thoughts!
Phil Sturgeon
2011-07-15
I'd be surprised if BP still uses Matchbox, if so they need to look into that!
Moving from Matchbox to Modular Extensions is pretty simple, you just need to re-write your cross-loading requests from $this->load->module_model('foo', 'bar') to the more standard $this->load->model('foo/bar') and re-work your modular routes.
In Matchbox all modular routes are equal and can potentially override each other, in Modular Extensions they are for routing to controllers within the module specified in the first URI segment. In my opinion much more useful.