简体   繁体   English

带前缀的Codeigniter路由模式

[英]Codeigniter route pattern with prefix

I'm working on Codeigniter 3 route mechanism, my application is multi branch, I tried google mail url pattern like app.com/p/branch_id/controller/method/param1/param2/etc but some cases it doesn't need prefix p/branch_id/ for admin or global setting. 我正在使用Codeigniter 3路由机制,我的应用程序是多分支,我尝试了类似app.com/p/branch_id/controller/method/param1/param2/etc类的google邮件url模式,但在某些情况下不需要前缀p/branch_id/用于管理员或全局设置。 I think my rule isn't effective. 我认为我的规则无效。

$route['p/(:num)/(:any)'] = '$2';
$route['p/(:num)/(:any)/(:any)'] = '$2/$3';
$route['p/(:num)/(:any)/(:any)/(:any)'] = '$2/$3/$4';
$route['p/(:num)/(:any)/(:any)/(:any)/(:any)'] = '$2/$3/$4/$5';

I want achieve
/p/1/booking -> route to controller booking
/p/1/booking/create -> route to controller booking action create()
/p/1/booking/view/1 -> route to controller booking action view($id)

also same thing when user visit
/booking -> route to controller booking
/booking/create -> route to controller booking action create()
/booking/view/1 -> route to controller booking action view($id)

How i write the rule for number unknown possible of parameters, when $route['p/(:num)/(:any)'] = '$2'; $route['p/(:num)/(:any)'] = '$2';时,我如何为参数的未知数编写规则$route['p/(:num)/(:any)'] = '$2'; just routing index controller only. 仅路由索引控制器而已。

I am sure it will work. 我相信它会起作用。

$route['p/(:num)/(:any)'] = 'booking/action/$1/$2';
$route['p/(:num)/(:any)/create'] = 'booking/create/$1/$2';
$route['p/(:num)/(:any)/view/(:num)'] = 'booking/view/$1/$2/$3'; //$3 is record no.

Addition 加成

Or if you want to make action as dynamic variable. 或者,如果您想将动作作为动态变量执行。

$route['p/(:num)/(:any)'] = 'booking/defaultAction/$1/$2';
$route['p/(:num)/(:any)/(:any)'] = 'booking/defaultAction/$1/$2'; // here in default action you need to add condition that if its create then execute create functionality. or if its view then execute view funcitonality

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM