Welcome Guest, Not a member yet? Register   Sign In
URL routing when using HMVC
#1

[eluser]Yoosuf Muhammad[/eluser]
Hi Igniters,

Need a quick hand on setting custom route for my project.

the code works without any reoute definition as

Code:
http://myblog.local/posts/categories/show/1

but I want to access it as following;

Code:
http://myblog.local/posts/1


Code:
$route['posts/(:any)'] = 'posts/categories/show/$3';


But my route declaration seems not working, please help me where i am doing the mistake
#2

[eluser]Otemu[/eluser]
This post should provide you with the answers you seek

http://stackoverflow.com/questions/14200...g-properly
#3

[eluser]hot_sauce[/eluser]
Add this in your routes.php config file application/config/routes.php
Auto generation routes
change your dir modules if necessary!
Code:
$dir_modules = APPPATH.'modules';
if (is_dir($dir_modules)){
foreach (scandir($dir_modules) as $module) {
  if ($module == '.' || $module == '..' || $module=='index.html') continue;
  $dir_c = $dir_modules.'/'.$module.'/controllers';
  if (is_dir($dir_c)){
   foreach (scandir($dir_c) as $item) {
    $item =  str_replace(".php","",$item);
    if ($item == '.' || $item == '..' || $item=='index.html') continue;
    $moduleT = $module.'/';
    if ($module == $item)
     $moduleT = '';
    $route[$moduleT.$item.'/(:any)'] = $moduleT.$item.'/$1';
    $route[$moduleT.$item] = $moduleT.$item.'/index/$0';
   }
  }
}
}




Theme © iAndrew 2016 - Forum software by © MyBB