CakePhp分页功能

CakePhp分页功能

1.Setting Up

download http://bakery.cakephp.org/articles/view/67
copy the code save as
 /app/controllers/components/pagination.php

download
http://bakery.cakephp.org/articles/view/68
copy the code save as
 /app/views/helpers/pagination.php

download
 http://bakery.cakephp.org/articles/view/69
copy the code save as
 /app/views/elements/pagination.thtml

If you can't download up, please give to your mailbox,I can give you.

2.Create/modify the Controller

<?php 
class PostsController extends AppController
{
    var $name = 'Posts'; // for PHP4 installs
    var $components = array ('Pagination'); // Added
    var $helpers = array('Pagination'); // Added

    function index() {    
        $criteria=NULL;
        list($order,$limit,$page) = $this->Pagination->init($criteria); // Added
        $data = $this->Post->findAll($criteria, NULL, $order, $limit, $page); // Extra parameters added
        
        $this->set('data',$data);
    }
}
?>

3.Create/modify the View
<h1>Paginated Posts Index</h1>
<table>
<?php
$pagination->setPaging($paging); // Initialize the pagination variables
$th = array (
            $pagination->sortBy('id'),
            $pagination->sortBy('title'),
            $pagination->sortBy('created')
); // Generate the pagination sort links
echo $html->tableHeaders($th); // Create the table headers with sort links if desired

foreach ($data as $output)
{
    $tr = array (
        $output['Post']['id'],
        $html->link($output['Post']['title'], "/Posts/View/{$output['Post']['id']}"),
        $output['Post']['created']
        );
    echo $html->tableCells($tr,array('class'=>'altRow'),array('class'=>'evenRow'));
}
?>
</table>
<? echo $this->renderElement('pagination'); // Render the pagination element ?>

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值