获取GET""在laravel变量 [英] Getting GET "?" variable in laravel

查看:492
本文介绍了获取GET""在laravel变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我使用REST和Laravel创建API,我在下面的这个文章。一切都很顺利,但我要地图GET请求来识别变量使用?。例如:<?code>域/ API / V1 /待办事项启动= 1&安培;极限= 2

Hello I'm creating API using REST and Laravel, I was following this article. Everything went well, but I want to map GET request to recognise variable using "?". For example: domain/api/v1/todos?start=1&limit=2

我的routes.php文件:

My routes.php :

Route::any('api/v1/todos/(:num?)', array('as' => 'api.todos', 'uses' => 'api.todos@index'));

我的控制器/ API / todos.php:

my controllers/api/todos.php :

class Api_Todos_Controller extends Base_Controller {

    public $restful = true;

    public function get_index($id = null) {
        if(is_null($id)) {
            return Response::eloquent(Todo::all(1));

        } else {
            $todo = Todo::find($id);
            if (is_null($todo)) {
                return Response::json('Todo not found', 404);
            } else {
                return Response::eloquent($todo);   
            }
        }
    }
}

如何识别使用get参数? ?
谢谢你,对不起我的英语不好

How to recognise get parameter using "?" ? Thank you and sorry for my bad English

推荐答案

看一看的 $ _GET $ _REQUEST 超全局变量。像下面的内容将努力为您例如:

Take a look at the $_GET and $_REQUEST superglobals. Something like the following would work for your example:

$start = $_GET['start'];
$limit = $_GET['limit'];

修改

根据这个帖子在laravel论坛,你需要使用输入::得到(),如

$start = Input::get('start');
$limit = Input::get('limit');

另请参阅: http://laravel.com/docs/input#input

这篇关于获取GET&QUOT;&QUOT;在laravel变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆