将参数从Laravel中的路由传递给控制器 [英] Passing parameter to controller from route in laravel
本文介绍了将参数从Laravel中的路由传递给控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是LARAVEL 3的问题
给出以下路线
Route::get('groups/(:any)', array('as' => 'group', 'uses' => 'groups@show'));
还有我要使用的网址,
http://www.example.com/groups/1
我希望能够在控制器中使用(:any)
值.
I would like to be able to use the (:any)
value in my controller.
我的控制器看起来像
class Groups_Controller extends Base_Controller {
public $restful = true;
public function get_show($groupID) {
return 'I am group id ' . $groupID;
}
}
这怎么可能?我已经尝试了包括以下内容在内的一些东西
How is this possible to do? I have tried a few things including the following
Route::get('groups/(:any)', array('as' => 'group', 'uses' => 'groups@show((:1))'));
但是它不起作用.
更新
每次我尝试传递上面显示的参数时,我都会收到404错误.
Anytime I try to pass in the arguments as show above i get a 404 error.
感谢您的帮助!
推荐答案
添加参数不需要任何特殊操作.就像您拥有它一样.
You don't need anything special for adding paramaters. Just like you had it.
Route::get('groups/(:any)', array('as' => 'group', 'uses' => 'groups@show'));
class Groups_Controller extends Base_Controller {
public $restful = true;
public function get_show($groupID) {
return 'I am group id ' . $groupID;
}
}
这篇关于将参数从Laravel中的路由传递给控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文