路由查询字符串

问题描述:

我有一个形式,我的模板文件:路由查询字符串

   {{ Form::open(array('route' => 'get.index', 'method' => 'get')) }} 
        {{ Form::label('order', 'Order by') }} 
        {{ Form::select('order' , array('firstname' => 'First Name', 'lastname' => 'Last Name', 'state' => 'State')) }} 
        {{ Form::submit('Order results') }} 
       {{ Form::close() }} 

提交时,这种形式输出一个GET查询变量名称的顺序,所以我的网址是:

http://my.app/?order=firstname 

这是在get.index路线:

Route::get('/', array('uses' => '[email protected]', 'as' => 'get.index')); 

有一个简单的方法来从一个改变URL上面类似 http://my.app/order/fistname/

你可以有这样的路线的唯一方法是使用:

Route::get('/order/{type}', array(
    'uses' => '[email protected]', 
    'as' => 'get.index' 
)); 

然后你就可以在你的控制器方法使用type参数:

public function index($type) { 

} 

但它会除非您在JavaScript中格式化表单动作值以适应此路线,否则不会与您的实际表单一起工作。

但是,如果你可以使用的东西比你可以轻松地用HTML标签a做一个形式一样,对于为例:

Order by: 
<a href="{{ route('get.index', 'firstname') }}">firstname</a> 
<a href="{{ route('get.index', 'lastname') }}">lastname</a>