How To Using CPagination alone

Hi Gurus,

I want to use CPagination class alone.

here I have a controller




class ProductsController extends Controller {

    protected $_model;

    public $layout = 'admin1';


    public function actionList(){

        $model = $this->loadModel();

        $criteria = new CDbCriteria();

        $criteria->condition = "status = 1";

        $page = new CPagination(Products::model()->count($criteria));

        $page->pageSize = 10;

        $page->applyLimit($criteria);

        $this->render('list',array(

            'model' => $model,

            'page' => $page

        ));

    }


    public function loadModel($id = ''){

        

        if($id > 0){

            $this->_model = Products::model()->findByPk($id,'status = 1');

        }else{

            $this->_model = Products::model()->findAll('status = 1');

        }

        return $this->_model;

    }

}




and here is the view:




<h1>Product List</h1>

<div style="position:relative;">

<?php

    $i = 1;

    foreach($model as $result){

            echo '<div style="margin:10px;padding:5px;border:1px solid #CFCFCF;">';

            echo '<div style="font-weight:bold;font-size:15px;">'.$result->title.'</div>';

            echo '<div>'.$result->desc.'</div>';

            echo '<div style="font-size:15px;">'.Products::number_format($result->price).'</div>';

            echo '</div>';

    }

    var_dump($page) // don't know how to use this variable

?>

</div>




see that $page on my list. I just var_dump($page) because, I don’t know how to process this variable.

the result of my var_dump($page) is:




object(CPagination)#30 (<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> { ["pageVar"]=>  string(4) "page" ["route"]=>  string(0) "" ["params"]=>  NULL ["_pageSize:private"]=>  int(10) ["_itemCount:private"]=>  string(1) "5" ["_currentPage:private"]=>  int(0) ["_e:private"]=>  NULL ["_m:private"]=>  NULL } 



any Idea gurus??

please help??

thanks

The easiest way is to use a CLinkPager or CListPager widget to show the data in the pager:


<? $this->widget('CLinkPager', array('pages' => $pages)); ?>

If that’s not what you are looking for, you can use the methods defined for CPagination directly. The class documentation can be found here:

http://www.yiiframework.com/doc/api/CPagination

Regards,

pieter

great sir, thanks works :)