开发者

URI re-routing in codeigniter

开发者 https://www.devze.com 2022-12-19 13:06 出处:网络
I\'m using URI re-routing in CI to make better URLS. An example here would be: $route[\'use开发者_运维问答rs/(:any)\'] = \"users/index/$1\";

I'm using URI re-routing in CI to make better URLS. An example here would be:

$route['use开发者_运维问答rs/(:any)'] = "users/index/$1";

The aim here is to get rid of the index from URL. This works well. However it stops me from being able to access any functions in the users controller, for example

mywebsite.com/users/messages

Just redirects to the users/index. Is there a way around this?


Define the list of methods you wish to keep then let the rest wildcard match:

$route['users/(messages|login|something)'] = "users/$1";
$route['users/(:any)'] = "users/index/$1";


Hi I'm not familiar with CI but i have a similar routing system. The (:any) works as a sort of catch all. When my router checks the routing rules it stops checking if it has found an exact match. So then the answer would be to just add another functions route before the catch all. Like

$route['users']                   = "users/index/";
$route['users/messages/(:any)']   = "users/checkmessages/$1";
$route['users/(:any)']            = "users/$1";

Not sure how CI handles this but i can think of something like the first URL part is the class and the second the function. The router or the controller module should have the intelligence to start calling the function even without the routing table. The routing table should only be used in case of "other callable names" like i did above with the messages/checkmessages thingy.

hope that gets you going.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号