有没有办法删除或隐藏网址中的控制器名称?笨

Ajm*_*eel 5 php url codeigniter

我在php codeigniter中开发了一个项目.该项目已接近完成,但现在我的经理要我完全删除或隐藏URL中的控制器名称.我当前的网址如下所示:

http://www.sitename.com/Controller_Name/function_name

我的经理希望它看起来像这样:

http://www.sitename.com/function_name

请注意,我的项目中有10个以上的控制器和许多功能.我想要一个适用于所有人的方法.请帮忙.

Dan*_*das 7

你可以使用$route.

如果你只有一个Controller并且在那个控制器中functions你可以写下这样的东西:

$route['(:any)'] = "Controller_Name/$1";
Run Code Online (Sandbox Code Playgroud)

如果你有很多,Controllers你需要为每个指定function控制器指定.像这样:

$route['function1'] = "Controller_Name1/function1";
$route['function2'] = "Controller_Name1/function2";
$route['function3'] = "Controller_Name3/function3";
Run Code Online (Sandbox Code Playgroud)

你不能有重复 $route

这个$route数组应该位于:application/config/routes.php.

您可以在此处查看CI文档中有关路由的更多信息:https://www.codeigniter.com/userguide3/general/routing.html