Need some help with my code
I am using cakephp 1.26 and doing pagination. could you help me with the following code please? I ca开发者_如何学编程n't figure out what's wrong in the code.
$this->set('posts', $this->paginate = array('order'=>array('Post.created'=> 'DESC'), 'conditions'=>array('Post.zero'=>'0'), 'limit'='6'
)
);
In the .ctp file I have this:
<table>
<tr><td>
<?php echo $paginator->numbers(); ?>
<?php
echo $paginator->prev('Previous', null, null);
echo $paginator->next(' Next', null, null);
?>
</td></tr>
</table>
Your code is bad. You cannot make the assignment within the function call. Either do:
$this->set('posts', $this->paginate('Post',array(
'order' => array('Post.created' => 'DESC'),
'conditions' => array('Post.zero' => '0'),
'limit' => '6'
)));
or:
$this->paginate = array(
'order' => array('Post.created' => 'DESC'),
'conditions' => array('Post.zero' => '0'),
'limit' => '6');
$this->set('posts', $this->paginate('Post'));
);
Shouldn't your code be:
$this->set('posts', $this->paginate = array(
'order' => array('Post.created' => 'DESC'),
'conditions' => array('Post.zero' => '0'),
'limit' => '6')
);
?
You can try to make the process more clear.
$this->paginate['Post'] = array('order'=>array('Post.created'=> 'DESC'), 'conditions'=>array('Post.zero'=>'0'), 'limit'='6'));
$posts = $this->paginate('Post');
$this->set(compact('posts'));
精彩评论