Laravel 4:如何传递多个可选参数 [英] Laravel 4 : How to pass multiple optional parameters

查看:404
本文介绍了Laravel 4:如何传递多个可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是laravel的新手,我真的很难理解如何传递多个可选的url参数.

I am new to laravel and I am really struggling to understand how to pass multiple optional url parameters.

将3个可选参数传递给控制器​​时,路由的标准编码方式是什么?

What is the standard way to code routes when passing 3 optional parameters to the controller?

还有一种方法可以对路由进行编码,以允许将命名参数传递给控制器​​?

Also is there a way to code a route to allow named parameters to be passed to the controller?

例如

public/test/id=1&page=2&opt=1
or 
public/test/id=1/page=2/opt=1

感谢您的帮助

推荐答案

如果您有多个可选参数

Route::get('test',array('as'=>'test','uses'=>'HomeController@index'));

在您的控制器内部

 class HomeController extends BaseController {
    public function index()
    {
       // for example public/test/id=1&page=2&opt=1
       if(Input::has('id'))
           echo Input::get('id'); // print 1
       if(Input::has('page'))
           echo Input::get('page'); // print 2
       //...
    }
 }

这篇关于Laravel 4:如何传递多个可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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