本文介紹了Cakephp 3.x 中的分頁排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在 cakephp 3.x 中我不能在 find 中做分頁順序
In cakephp 3.x i can't do paginate order in a find
這是我的控制器:
//AgentsController.php
public function show()
{
$agents = $this->Agents->find()
$this->set('agents', $this->paginate($agents));
}
這里是我的部分觀點
//show.ctp
<!-- ....... -->
<table class="table table-striped">
<thead>
<tr>
<th>
<?php echo $this->Paginator->sort('full_name', 'Nome', array('escape' => false)); ?>
</th>
<th>
<?php echo $this->Paginator->sort('username', 'Email', array('escape' => false)); ?>
</th>
<th>
<?php echo $this->Paginator->sort('regions', 'Regioni', array('escape' => false)); ?>
</th>
</tr>
</thead>
<!-- ....... -->
我錯在哪里?
推薦答案
分頁器將阻止任何按您正在使用的查詢的主表中不存在的列進行排序的嘗試.在這種情況下,您有 2 個選擇.第一個選項是更改排序鏈接以告訴 cake 該列屬于相關表:
The Paginator will block any attempt of sorting by a column that does not exist in the primary table of the query you are using. In this case you have 2 options. The first option is changing the sort links to tell cake that the column belongs to a related table:
<?php echo $this->Paginator->sort('Users.full_name', 'Nome'); ?>
或者您可以在組件中告訴它允許按給定的一組列進行排序:
Or you can tell it in the component that sorting by a given set of columns is allowed:
$this->paginate = ['sortWhitelist' => ['full_name', 'username']]
這篇關于Cakephp 3.x 中的分頁排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!