Cakephp 中的分页排序 3.x

Pagination Sort in Cakephp 3.x

在 cakephp 中 3.x 我无法在查找中进行分页排序

这是我的控制器:

//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 将阻止任何按您正在使用的查询的主要 table 中不存在的列进行排序的尝试。在这种情况下,您有 2 个选择。第一个选项是更改排序链接以告诉蛋糕该列属于相关的 table:

<?php echo $this->Paginator->sort('Users.full_name', 'Nome'); ?>

或者您可以在组件中告诉它允许按一组给定的列进行排序:

$this->paginate = ['sortWhitelist' => ['full_name', 'username']]

尝试:

$this->paginate = ['sortWhitelist' => ['full_name','username','regions'],'limit' => 3];

这也将设置分页限制。