Codeigniter路由模式与前缀
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeigniter路由模式与前缀相关的知识,希望对你有一定的参考价值。
我正在研究Codeigniter 3路由机制,我的应用程序是多分支,我尝试了像app.com/p/branch_id/controller/method/param1/param2/etc
的谷歌邮件网址模式,但有些情况下它不需要前缀p/branch_id/
用于管理员或全局设置。我认为我的规则无效。
$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)
当$route['p/(:num)/(:any)'] = '$2';
只是路由索引控制器时,我如何为数字未知可能的参数编写规则。
答案
我相信它会奏效。
$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.
加成
或者,如果您想将动作作为动态变量。
$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
以上是关于Codeigniter路由模式与前缀的主要内容,如果未能解决你的问题,请参考以下文章
Codeigniter - AngularJS 路由导致 404