duanbing2963 2013-11-03 14:02
浏览 71
已采纳

Laravel 4 restful controller GET参数

In order to add parameter to a GET method, I know that I have to add {parameter} in the route like the following

Route::get('example/search/{id}', 'ExampleController@exampleMethod')

However, is there a way to do this using the RESTful controller like the following?

routes.php

Route::controller('example', 'ExampleController')

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. I wonder if there is a way to solve this without having to add individual Route::get routes.

  • 写回答

1条回答 默认 最新

  • duanmao9918 2013-11-03 15:41
    关注
    <?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:

    enter image description here

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料