在cakephp中实现分页

时间:2011-10-07 06:42:09

标签: cakephp cakephp-1.2

我希望在视图页面的搜索结果中实现分页。目前在控制器中,我将其限制为10个结果来查看。我如何实施分页?

在我的控制器中,

var $name = 'Searches';
var $components = array('Auth');
var $uses = array('User','Passion');
$users = $this->User->find('all',array('limit'=>10,'conditions'=>$final_conditions,'fields'=>array('User.*')));

在我的视图页面中,

    <?php foreach ($search_fields as $user): ?> 
        <tr>
            <?php //debug($search_fields);?>
            <td><?php echo $user['User']['firstName']; ?></td>
            <td><?php echo $user['User']['lastName']; ?></td>
            <td><?php echo $user['User']['email']; ?></td>
            <td><?php echo $user['User']['displayName']; ?></td>
            <td><?php echo $user['User']['gender']; ?></td>
        </tr>
    <?php endforeach; ?>

1 个答案:

答案 0 :(得分:1)

控制器

$this->paginate = array(
'conditions' => $final_conditions,
'limit' => 10
);

$users = $this->paginate('User');

在视图中,您只需使用与http://book.cakephp.org/view/166/Pagination-in-Views

相同的内容