CodeIgniter with Wiredesignz HMVC routing

Kobus Myburgh picture Kobus Myburgh · Mar 26, 2013 · Viewed 9.2k times · Source

I am using HMVC and created a module called user. Inside modules/user/config directory, I have routes.php, using the same format as application/config/routes.php.

In application/config/routes.php I have the following route:

$route['login'] = 'user/login';

This works great, buit when I move it to application/modules/user/config/routes.php, it does not work. I get a 404 error.

According to HMVC docs (https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc), you have to create routes as follows:

$route['module_name'] = 'controller_name';

This means I will have to do it like this:

$route['user'] = 'user';

This causes the 404, however, even if I did not get the 404, this is not quite what I have in mind. I still want to keep my routing to work as /login goes to user/login.

Any ideas would be greatly appreciated!

Thanks!

Answer

Brian picture Brian · Apr 9, 2013

I had the same exact problem as you, unfortunately the way Wiredesignz created the extension it requires that the path start with the module name itself if you put the routes file inside the module itself. That is the only way it will look at the routes file if it is placed inside a module. With that said it already knows the module name at that point, so you need to simply specify the controller and method that you want it to route to. So in your routes.php file inside of your module config directory, if you put this:

$route['yourmodule/some-route'] = "yourcontroller/yourmethod";

or in other words:

$route['user'] = 'user/login';

That would work I believe. However I still wanted more than this. I wanted to be able to use routes that may or may not have the module name. Due to this I had to extend the module to make this happen, and you can find the work I did here if this helps:

https://github.com/brianwozeniak/codeigniter-modular-extensions-hmvc

This would then allow you to use the route you wanted such as:

$route['login'] = 'user/login';

Even with that routes.php placed inside the module's config directory.