[英]Pagination Sort in Cakephp 3.x
在cakephp 3.xi中找不到分頁順序
這是我的控制器:
//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>
<!-- ....... -->
哪里錯了?
Paginator將阻止任何按您正在使用的查詢的主表中不存在的列進行排序的嘗試。 在這種情況下,您有2個選項。 第一個選項是更改排序鏈接以告訴蛋糕列屬於相關表:
<?php echo $this->Paginator->sort('Users.full_name', 'Nome'); ?>
或者您可以在組件中告訴它允許按給定的一組列進行排序:
$this->paginate = ['sortWhitelist' => ['full_name', 'username']]
嘗試:
$this->paginate = ['sortWhitelist' => ['full_name','username','regions'],'limit' => 3];
這也將設置分頁限制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.