[英]Laravel 4 restful controller GET parameter
In order to add parameter to a GET method, I know that I have to add {parameter}
in the route like the following 为了向GET方法添加参数,我知道我必须在路由中添加
{parameter}
,如下所示
Route::get('example/search/{id}', 'ExampleController@exampleMethod')
However, is there a way to do this using the RESTful controller like the following? 但是,有没有办法像下面这样使用RESTful控制器来做到这一点?
routes.php routes.php文件
Route::controller('example', 'ExampleController')
ExampleController.php ExampleController.php
public function getSearch($id){
//do something with $id
}
The above doesn't work because the routes.php
doesn't expect a parameter to getSearch
method. 上述不起作用,因为
routes.php
不指望一个参数getSearch
方法。 I wonder if there is a way to solve this without having to add individual Route::get
routes. 我想知道是否有一种无需添加单个
Route::get
路由即可解决此问题的方法。
<?php
// ExampleController.php
class ExampleController extends BaseController {
public function getSearch($id = null){
if ($id == null) {
return 'no id';
}
return $id;
}
}
// routes.php
Route::controller('example', 'ExampleController');
?>
php artisan routes
: php artisan routes
:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.