[英]how to pass parameters to the main action of a controller in codeigniter?
I want to pass parameters to the main action of a controller like so : 我想像这样将参数传递给控制器的主要动作:
http://www.site.com/controller/index/param1/param2
but I DON'T want to have to write the 'index' action. 但我不想写“索引”操作。 So :
因此:
http://www.site.com/controller/param1/param2
How can I do this in codeigniter ? 如何在Codeigniter中执行此操作? Thanks :)
谢谢 :)
You will have to modify your routes.php
as the route default would be to controller/method
您将必须修改您的
routes.php
因为默认路由是controller/method
And explicitly define your route of 并明确定义您的路线
$route['blogs/(:any)/(:any)'] = "blogs/index/$1/$2";
Word to the wise about routing, once you set down this path of 'prettying up' the controller/method, you will need to define it for all methods in your controller: 明智地讲路由,一旦您设置了“修饰”控制器/方法的路径,就需要为控制器中的所有方法定义它:
$route['blogs/load/(:any)'] = "blogs/load/$1";
$route['blogs/delete/(:any)'] = "blogs/delete/$1";
As you won't be able to just call /blogs/load/4332
it will think 'load' is var 1 and '4332' is var 2. 由于您将无法调用
/blogs/load/4332
因此它将认为“ load”为var 1,而“ 4332”为var 2。
Reference: http://codeigniter.com/user_guide/general/routing.html 参考: http : //codeigniter.com/user_guide/general/routing.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.