[英]Need a hand using routes in CodeIgniter
I would like to get URLs like http://mysite.com/user/1
to route to the function get($id) {...}
of my Controller User
. 我想获取诸如http://mysite.com/user/1
类的URL,以路由到我的Controller User
的功能get($id) {...}
。
I have tried the following in order to do so, but I get a 404 Error, Page Not Found
rather than the output Hello, User 1
. 为了做到这一点,我尝试了以下操作,但出现404错误, Page Not Found
而不是输出Hello, User 1
。
Please can you tell me where I am going wrong?! 请您告诉我我要去哪里错了!!
//routes file
$route['user/:id'] = "user/$1";
//user controller
function get($id) {
echo "Hi, User $id";
}
Edit---- 编辑 - -
My code works perfectly when I run http://mysite.com/user/get/1
, but not when I run http://mysite.com/user/1
. 我的代码完美的作品,当我运行http://mysite.com/user/get/1
,但不是当我运行http://mysite.com/user/1
。
This should work: 这应该工作:
$route['user/(:num)'] = "user/get/$1";
More info at http://ellislab.com/codeigniter/user-guide/general/routing.html 有关更多信息,请访问http://ellislab.com/codeigniter/user-guide/general/routing.html
try this: 尝试这个:
$route['user/get/'] = "user/";
or rename get function as index function. 或将get函数重命名为index函数。 probably no need to any changes in routes.php that way. 可能不需要以这种方式对route.php进行任何更改。
This way: 这条路:
['user/(:any)'] = user/get/$1;
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.