Laravel 4:从控制器获取 url 参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19336557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4: get url parameter from controller
提问by Timo Güntner
I'm new to laravel 4 and I'm currently having the following problem: In my routes.php I have the line:
我是 laravel 4 的新手,目前遇到以下问题:在我的 routes.php 中,我有一行:
Route::get('maps/{map_type}', 'MapsController@loadMaps');
And in my MapsController I'd like to get the {map_type} to use it.
在我的 MapsController 中,我想让 {map_type} 使用它。
So my question: How can I retrieve map_type in my Controller?
所以我的问题是:如何在我的控制器中检索 map_type?
回答by Marwelln
Your first argument in your loadMaps
method is your map type.
您loadMaps
方法中的第一个参数是您的地图类型。
public function loadMaps($map_type) {
return $map_type;
}
Take a look at the first two code snippets on http://laravel.com/docs/controllers.
查看http://laravel.com/docs/controllers上的前两个代码片段。
回答by William Cahill-Manley
Controllers receive parameters as parameters in the called function:
控制器接收参数作为被调用函数中的参数:
class MapsController extends BaseController {
public function loadMaps($map_type) {}
}
Check http://laravel.com/docs/controllers#basic-controllersfor more info
查看http://laravel.com/docs/controllers#basic-controllers了解更多信息