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

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

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析