php - Cakephp 3.x 中的分页排序

标签 php cakephp cakephp-3.0

在 cakephp 3.x 中,我无法在查找中执行分页顺序

这是我的 Controller :

//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']]

关于php - Cakephp 3.x 中的分页排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28948164/

相关文章:

php - 手动安装 cakephp 3,没有 Composer

php - 错误 : SQLSTATE[HY000]: General error: 8 attempt to write a readonly database cakephp

php - 从 CakePHP 中的相关项目项获取项目的总计

cakephp - CakePHP 3 上未找到类 'Locale' 问题

php - 无法连接到数据库服务器

cakephp 重定向在服务器上不起作用

cakephp - 如何处理我的 CakePHP 应用程序的 robots.txt?

php - cakephp bake SQLSTATE[HY000] [2002] 没有那个文件或目录

php - 使用 php 的 ics 附件未反射(reflect)在 Outlook 日历中?

php - ob_start 和 ob_gzhandler 函数到底做了什么