Yii Framework Forum: How To Using CPagination alone - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Using CPagination alone Rate Topic: -----

#1 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 12 March 2010 - 12:04 AM

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 (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
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   pclaerhout 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 08-December 08

Posted 12 March 2010 - 02:56 AM

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.yiiframew...api/CPagination

Regards,

pieter

View PostDan Din Dun, on 12 March 2010 - 12:04 AM, said:

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 (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

0

#3 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 12 March 2010 - 06:51 AM

View Postpclaerhout, on 12 March 2010 - 02:56 AM, said:

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.yiiframew...api/CPagination

Regards,

pieter


great sir, thanks works :)
Thanks and Kind Regards
------
DanDinDun
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users