简体   繁体   English

route.php和控制器(codeigniter)

[英]routes.php and controllers (codeigniter)

I have two controllers 1- site 2- management 我有两个控制器1-站点2-管理

the first controllers(Site) is work successfuly the second controllers(Managemnt) is not work. 第一个控制器(站点)成功工作,第二个控制器(Managemnt)不工作。

I don't know what is the errror 我不知道什么是错误

I change the routes.php but still doesn't work(managment) 我更改了routes.php,但仍然无法正常工作(管理)

$route['default_controller'] = "site";
$route['(:any)'] = "site/$1";
$route['Administration'] = "Administration/index";
$route['Administration/([a-z])'] = 'Administration/$1';

this links work: 此链接有效:

example.com/hotel/12312 example.com/hotel/12312

example.com/contact example.com/contact

example.com/city/newyork example.com/city/newyork

example.com/Administration example.com/Administration

but this links doesn't works: 但是此链接不起作用:

example.com/Administration/hotels example.com/Administration/hotels

example.com/Administration/add_new example.com/Administration/add_new

example.com/Administration/cities example.com/Administration/cities

where is the problem pls because I tired to solve this problem 问题在哪里,因为我累了要解决这个问题

thaks 塞克斯

It has to do with the order in witch you are giving route directives. 它与您给路线指令的女巫的顺序有关。 Code igniter routes requests from top to bottom, so if you want your $route['Administration'] to precede $route['(:any)'] you have to set it first. 代码点火器从上到下路由请求,因此,如果您希望$ route ['Administration']在$ route ['(:any)']之前,则必须先设置它。

 $route['default_controller'] = "site"; $route['Administration/([az])'] = 'Administration/$1'; $route['Administration'] = "Administration/index"; $route['(:any)'] = "site/$1"; 

I would allways sugest putting (:any) routes at the end so they don't overwrite more specific routes. 我总是建议将(:any)路由放在最后,这样它们就不会覆盖更具体的路由。

I had same problem & I get this working: 我遇到了同样的问题,并且可以正常工作:

$route['default_controller'] = "welcome";
$route['([a-z-A-Z1-9_]+)'] = "site";
$route['management']="management";
$route['404_override'] = '';

it may help you! 它可以帮助您!

I'm not familiar with Codeigniter routing, but to me looks like everything is matching $route['(:any)'] = "site/$1"; 我对Codeigniter路由不熟悉,但对我来说似乎一切都与$route['(:any)'] = "site/$1";匹配$route['(:any)'] = "site/$1"; before it ever reaches your Administration routes. 在到达您的管理路线之前。 Try moving it below everything else...you might also have to switch your Administration routes for the ([az]) to match 尝试将其移至其他所有内容之下...您可能还需要切换管理路线,以使([az])匹配

$route['default_controller'] = "site";
$route['Administration/([a-z])'] = 'Administration/$1';
$route['Administration'] = "Administration/index";
$route['(:any)'] = "site/$1";

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

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