how to create Codeigniter route that doesn't override the other controller routes?

早过忘川 提交于 2019-12-03 08:19:06

You're going to have to explicitly define all of those routes. Otherwise you will always end up at the "user_controller".

$route['signup'] = "signup";
$route['(:any)'] = "user/display/$1";

or something similar. They are ran in order, so what ever is defined first, is going to happen first. So if you catch (:any), you're going to send ANYTHING to that controller.

Also keep in mind that you can use regular expressions, so if you know there is always going to be a '.' in there, you could test for that.

You can also use a foreach statement for this. That way you can keep your controllers in a nice neat list.

$controller_list = array('auth','dashboard','login','50_other_controllers');

foreach($controller_list as $controller_name)
{
    $route[$controller_item] = $controller_name;
}

$route['(:any)'] = "user/display/$1";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!