Codeigniter HVMC modular seperation extension URL rewrite / routing

笑着哭i 提交于 2019-12-01 12:26:58

问题


Ive been using HVMC modular extension, and its working great, but Im having trouble figuring out how to use, and if it is possible to use URL routing with HVMC.

Basically, I have a module called “site”, which is my main default site controller. All of the other modules I am not using directly, I am only using them by calling echo modules::run(‘controller/method’);—So basically I just want to remove “site” from the URL so that all the methods within the site module/controller appear without the word “site” in it.

Can anyone tell me if this can be done with HVMC modular extensions?

Any help much appreciated!


回答1:


For completeness I have been researching my own solution to this issue and the removal of the "site" prefix on the URI string can be achieved by adding the following into the routes.php config file.

$route['(:any)'] = "site/$1";
$route['default_controller'] = "site";



回答2:


I also worked since 3 years in CI HMVC, and some of my routing examples is there, it may help you.

I define 2 types of module here one is site and another is admin.

1>Routing for admin:

/*ADMIN is a constant, you can define anything like admin or backend etc. */
/*Example: admin/login*/
$route[ADMIN.'/([a-zA-Z]+)'] = function($controller){ 
    return 'admin/'.strtolower($controller);
};

/*Example: admin/user/listing*/
$route[ADMIN.'/([a-zA-Z]+)/(:any)'] = function($controller, $function){ 
    return 'admin/'.strtolower($controller).'/'.str_replace("-","_",strtolower($function));
};

/*Example: admin/user/edit/LU1010201352*/
$route[ADMIN.'/([a-zA-Z]+)/(:any)/(:any)'] = function($controller,$function,$param) { 
    return 'admin/'.strtolower($controller).'/'.str_replace("-","_",strtolower($function)).'/'.$param;
};

/*Example: admin/user/assign-group/LU1010201352/G2010201311*/
$route[ADMIN.'/([a-zA-Z]+)/(:any)/(:any)/(:any)'] = function($controller,$function,$param,$param1){ 
    return 'admin/'.strtolower($controller).'/'.str_replace("-","_",strtolower($function)).'/'.$param.'/'.$param1;
};

2>Routing for site:

$route['([a-zA-Z]+)'] = function($controller) {
    return 'site/'.strtolower($controller);
};  

$route['([a-zA-Z]+)/(:any)'] = function($controller,$function){
    return 'site/'.strtolower($controller).'/'.str_replace("-","_",strtolower($function));
};

$route['([a-zA-Z]+)/(:any)/(:any)'] = function($controller,$function,$param) {
    return 'site/'.strtolower($controller).'/'.str_replace("-","_",strtolower($function)).'/'.$param;
};

$route['([a-zA-Z]+)/(:any)/(:any)/(:any)'] = function($controller,$function,$param,$param1) {
    return 'site/'.strtolower($controller).'/'.str_replace("-","_",strtolower($function)).'/'.$param.'/'.$param1;
};

It is totally dynamic. You can create lots of controller inside any module. If you want to add more module then you just make another block of routing like 1 or 2.



来源:https://stackoverflow.com/questions/3380174/codeigniter-hvmc-modular-seperation-extension-url-rewrite-routing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!