繁体   English   中英

Pagination在Cakephp 3.x中排序

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM