简体   繁体   English

Codeigniter中的路由问题

[英]Routing issues in Codeigniter

I am developing a web application with codeigniter. 我正在使用Codeigniter开发Web应用程序。 I have created a folder in controllers with name "Administration". 我已经在控制器中创建了一个名为“ Administration”的文件夹。 Inside this folder, i have kept all my controllers pertaining to the administration panels. 在此文件夹中,我保留了所有与管理面板有关的控制器。

Now, i want that if any user types the url as www.mywebsite.com/administration, the user should be redirected to the respective controller whatever comes as the next segment after administration. 现在,我希望如果有任何用户将URL键入为www.mywebsite.com/administration,则应将用户重定向到相应的控制器,而不管管理后的下一部分。 like if user types wwww.mywebsite.com/administration/login, then login controller should be executed. 例如,如果用户键入wwww.mywebsite.com/administration/login,则应执行登录控制器。 Well this is a pretty obvious thing. 好吧,这很明显。

Now what i want is, when someone types anything www.mywebsite.com/anything_else, it should be directed to some other controller by default. 现在我想要的是,当有人键入www.mywebsite.com/anything_else时,默认情况下应将其定向到其他控制器。 I am using following routes setup: 我正在使用以下路线设置:

$route['default_controller'] = 'welcome';
$route['404_override'] = ''; 
$route['administration/(:any)']='administration/$1';
$route['(:any)']='fetch_pages';

Please guide. 请指导。

I'd suggest you to do another approach: 我建议您采取另一种方法:

$route['default_controller'] = 'welcome';
$route['404_override'] = 'fetch_pages/index'; 

This solution makes you able to skip declaring the obvious administration route, and all other paths will be called through fetch_pages controller. 该解决方案使您能够跳过声明明显的administration路径,所有其他路径将通过fetch_pages控制器调用。

Read more about 404_override 进一步了解404_override

Depending on your needs, you may want to consider running show_404() when you can't find data based on uri . 根据您的需求,当找不到基于uri的数据时,您可能需要考虑运行show_404()

$route['^(?!administration).*'] = "fetch_pages";
$route['administration/(:any)']='Administration/$1';

I think you have created folder with capital letter "A" in Administration 我认为您在“管理”中创建了带有大写字母“ A”的文件夹

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

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