Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter hmvc routes not working properly

I installed HMVC by wiredesignz but the routes from application/modules/xxx/config/routes.php didn't get recognized at all. Here is an example:

In application/modules/pages/config/routes.php I have:

$route['pages/admin/(:any)'] = 'admin/$1';
$route['pages/admin'] = 'admin';

If I type the URL, domain.com/admin/pages/create it is not working, the CI 404 Page not found appears. If I move the routes to application/config/routes.php it works just fine.

How do I make it work without putting all the admin routes in main routes.php?

I searched the web for over 4 hours but found no answers regarding this problem. I already checked if routes.php from modules is loading and is working just fine, but any routes I put inside won't work.

like image 896
lesandru Avatar asked Jan 07 '13 17:01

lesandru


1 Answers

I found a way of making the routes from modules working just fine, I don't know if is the ideal solution but works fine so far:

open your application/config/routes.php and underneath $route['404_override'] = ''; add the following code:

$modules_path = APPPATH.'modules/';     
$modules = scandir($modules_path);

foreach($modules as $module)
{
    if($module === '.' || $module === '..') continue;
    if(is_dir($modules_path) . '/' . $module)
    {
        $routes_path = $modules_path . $module . '/config/routes.php';
        if(file_exists($routes_path))
        {
            require($routes_path);
        }
        else
        {
            continue;
        }
    }
}

the following solution works fine even if config folder or routes.php is missing from your module folder

like image 101
lesandru Avatar answered Sep 30 '22 20:09

lesandru