分页文档提供了有关如何为数据的分页链接添加排序的详细信息:
<?php echo $orders->appends(array('sort' => 'name', 'sort_dir'=>'asc'))->links();
生成这样的链接:
http://example.com/something?page=2&sort=name&sort_dir=asc
现在您有一个包含标题和值的表以及一系列可以单击的分页链接。让我们说我想将标题更改为可点击的链接,允许您按标题排序。我该如何生成该网址?
例如,假设我们当前的网址是我上面所说的:
http://example.com/something?page=2&sort=name&sort_dir=asc
我想点击&#34; NAME&#34;表头以便更改排序方向。我想要的URL是:
http://example.com/something?page=2&sort=name&sort_dir=desc
我有一个名为:AdminController.php的控制器,这是使用的方法:
public function getAdmins() {
// CACHE SORTING INPUTS
$allowed = array('first_name', 'last_name', 'email', 'activated', 'crated_at'); // add allowable columns to search on
$sort = in_array(Input::get('sort'), $allowed) ? Input::get('sort') : 'first_name'; // if user type in the url a column that doesnt exist app will default to first_name
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; // default desc
$action = null;
// select all admins Group = 1
$admins = DB::table('users')
->join('users_roles', 'users.id', '=', 'users_roles.user_id')
->where('users_roles.role_id', '=' ,0)
->orderBy($sort, $order)
->paginate($this->perpage);
// check for actions
if (!is_null(Input::get('action')))
{
$action = Input::get('action');
if ($action == "add")
{
$this->layout->content = View::make('admin.admins-add');
}
}
else
{
// get current counter admin counts
$counter = $admins->getFrom();
View::share('counter', $counter);
View::share('sort', $sort);
View::share('order', $order);
// share admin with template
View::share('admins', $admins);
$this->layout->content = View::make('admin.admins');
}
}
1)。如何在我的视图页面中显示Laravel中的列标题链接?
由于
答案 0 :(得分:0)
这就是你如何获得参数:
$params = Request::except(['sort','sort_dir']);
$sort_dir = (Request::get('sort_dir') == 'asc') ? 'desc' : 'asc';
$sort = 'whataverYourColumnIs';
$attributes = array_merge(['sort' => $sort, 'sort_dir' => $sort_dir], $params);
// and for the link for example:
link_to_action('AdminsController@getIndex', 'columnName', $attributes);