Php 视图中的laravel排序
我使用的是Laravel4.1,我被困在一个重复的任务中。 要对人员索引进行排序,我需要执行以下操作:Php 视图中的laravel排序,php,sorting,laravel,laravel-4,Php,Sorting,Laravel,Laravel 4,我使用的是Laravel4.1,我被困在一个重复的任务中。 要对人员索引进行排序,我需要执行以下操作: $sort = (!is_null(Input::get('sort')) ? Input::get('sort') : 'lastname'); //with 'lastname' being the default column to sort on. $order = (!is_null(Input::get('order')) ? Input::get('order') : 'asc
$sort = (!is_null(Input::get('sort')) ? Input::get('sort') : 'lastname');
//with 'lastname' being the default column to sort on.
$order = (!is_null(Input::get('order')) ? Input::get('order') : 'asc');
//'desc' is the default sort order.
$people = $people->orderBy($sort, $order);
$people = $people->paginate(20);
return View::make('people.index', array('people' => $people, 'sort' => $sort, 'order' => $order));
在视图self中,我创建了链接以使用此代码段进行排序,这也很好
<th>{{link_to_route(Route::currentRouteName(),'Lastname', array('sort' => 'lastname'))}}
@if ($order != 'asc')
<a href="{{URL::route(Route::currentRouteName(), array('sort' => $sort, 'order' => 'asc'))}}">
<i class="fa fa-sort-asc "></i>
</a>
@else
<a href="{{URL::route(Route::currentRouteName(), array('sort' => $sort, 'order' => 'desc'))}}">
<i class="fa fa-sort-desc "></i>
</a>
@endif</th>
{{link_to_route(route::currentRouteName(),'Lastname',array('sort'=>'Lastname'))}
@如果($order!=“asc”)
@否则
@恩迪夫
我的问题是我想对多个列进行排序。我的问题是:我是否必须在每个标题栏中复制下半部分?或者我可以把这个部件放在某个地方,这样我就可以在更简单的通话中使用它了
谢谢您可以使用表单宏:
//某处,例如在app/start/global.php中:
窗体::宏('headColumn',函数($sort,$order='asc'))
{
$url=url::route(route::currentRouteName(),数组('sort'=>$sort',order'=>$order));
返回“”;
});
然后在视图中:
<th>
{{ link_to_route(Route::currentRouteName(),'Lastname', array('sort' => 'lastname')) }}
@if ($order != 'asc')
{{ Form::headColumn($sort) }}
@else
{{ Form::headColumn($sort, 'desc') }}
@endif
</th>
{{链接到路由(路由::currentRouteName(),'Lastname',数组('sort'=>'Lastname'))}
@如果($order!=“asc”)
{{Form::headColumn($sort)}
@否则
{{Form::headColumn($sort,'desc')}
@恩迪夫
(我没有对此进行测试,但我认为想法应该很清楚。)
<th>
{{ link_to_route(Route::currentRouteName(),'Lastname', array('sort' => 'lastname')) }}
@if ($order != 'asc')
{{ Form::headColumn($sort) }}
@else
{{ Form::headColumn($sort, 'desc') }}
@endif
</th>