Pagination在Cakephp 3.x中排序

时间:2015-03-09 17:27:59

标签: php cakephp cakephp-3.0

在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>
<!-- ....... -->

哪里错了?

2 个答案:

答案 0 :(得分:11)

Paginator将阻止任何按您正在使用的查询的主表中不存在的列进行排序的尝试。在这种情况下,您有2个选项。第一个选项是更改排序链接以告诉蛋糕该列属于相关表:

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

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

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

答案 1 :(得分:-1)

尝试:

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

这也将设置分页限制。

相关问题