0

我正在使用 cakephp 1.26 并进行分页。你能帮我下面的代码吗?我无法弄清楚代码中有什么问题。

$this->set('posts', $this->paginate = array('order'=>array('Post.created'=> 'DESC'), 'conditions'=>array('Post.zero'=>'0'), 'limit'='6'
)                                           
                    );

在 .ctp 文件中,我有这个:

<table>
<tr><td>
       <?php echo $paginator->numbers(); ?>
<?php
    echo $paginator->prev('Previous', null, null);
    echo $paginator->next(' Next', null, null);
?> 

</td></tr>
</table>
4

3 回答 3

2

你的代码很糟糕。您不能在函数调用中进行分配。要么做:

$this->set('posts', $this->paginate('Post',array(
                  'order' => array('Post.created' => 'DESC'),
                  'conditions' => array('Post.zero' => '0'),
                  'limit' => '6'
                  )));

或者:

$this->paginate = array(
    'order' => array('Post.created' => 'DESC'),
    'conditions' => array('Post.zero' => '0'),
    'limit' => '6');

$this->set('posts', $this->paginate('Post'));
);
于 2010-07-08T09:57:27.103 回答
0

你的代码不应该是:

$this->set('posts', $this->paginate = array(
    'order' => array('Post.created' => 'DESC'),
    'conditions' => array('Post.zero' => '0'),
    'limit' => '6')
);

?

于 2010-07-07T07:50:25.583 回答
0

您可以尝试使过程更清晰。

$this->paginate['Post'] = array('order'=>array('Post.created'=> 'DESC'), 'conditions'=>array('Post.zero'=>'0'), 'limit'='6'));
$posts = $this->paginate('Post');
$this->set(compact('posts'));
于 2010-07-07T09:07:26.023 回答