【问题标题】:CakePHP paginator not paginatingCakePHP 分页器不分页
【发布时间】:2011-09-16 03:20:42
【问题描述】:

我有一个分页器如下:

    var $paginate = array(
        'order'=>array('ReleaseServer.server_environment'=>'ASC',
                           'ReleaseServer.server_name'=>'ASC'),
        'joins'=>array(
            array(
                'table' => 'release_server_to_components',
                'alias' => 'ReleaseServerToComponent',
                'type' => 'LEFT',
                'foreignKey' => false,
                'conditions'=> array('ReleaseServer.id = ReleaseServerToComponent.release_server_id')
            ),
            array(
                'table' => 'release_components',
                'alias' => 'ReleaseComponent',
                'type' => 'LEFT',
                'foreignKey' => false,
                'conditions'=> array('ReleaseServerToComponent.release_component_id = ReleaseComponent.id')
            )
        ),
        'group'=>array('ReleaseServer.id'),
        'contain' => array(
                'ReleaseServerToComponent' => array(
                        'ReleaseComponent' => array(
                            'Release'
                            )
                        )
                ),
        'limit' => 25,
    );

然后在我的控制器函数中执行以下操作:

$this->set('allServers', $this->paginate('ReleaseServer', $conditions));

$conditions 是查询的一些额外条件。

正如您在上面看到的,我将限制设置为 25。

然而,数据库中有 29 条记录,但页面只显示 25 条,页面说只有一页。

但是当一个人点击其中一个列标题对它们进行排序时,一些之前不存在的行会神奇地出现,而其他行会消失。为什么会这样?

如果您需要任何其他信息,请告诉我

更新

现在我发现问题出在paginate 变量的group 部分,但我需要它才能做到这一点,所以我不会得到多行相同的东西。

我该如何解决这个问题?

【问题讨论】:

    标签: php cakephp pagination


    【解决方案1】:

    我通过向我的模型添加一个新的paginateCount() 函数来解决它:

    function paginateCount($conditions = null, $recursive = 0, $extra = array())
    {
         $count = $this->find('count', array(
            'fields' => 'DISTINCT ReleaseServer.id',
            'conditions' => $conditions
        ));
        return $count;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 2018-04-30
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多