Yii 分页

//Controller
$model = new AutoSale;
$data = $model->getPageAutos(array('state'=>3),'id DESC', 0, 2);
$this->render('index',array(
   'autos'=>$data['autos'],
    'pages'=>$data['pages'],
     model'=>$model,
));
//Model
public function getPageAutos($terms, $order='id DESC', $page=0, $limit=8)
    {
        $criteria = new CDbCriteria;
        foreach($terms as $key=>$value)
        {
            $criteria->compare($key, $value);
        }
        $pages=new CPagination($this->count($criteria));
        $pages->pageSize=$limit;
        $pages->applyLimit($criteria); 
        $criteria->offset = $pages->currentPage*$pages->pageSize;
        $criteria->order = 'id DESC';
        $criteria->limit = $limit;
        return array(
            'autos'=>  $this->findAll($criteria),
            'pages'=>  $pages,
        );
    }

//View
$this->widget('CLinkPager', array(
                    'pages' => $pages,
                    'prevPageLabel' => '上一页',
                    'nextPageLabel' => '下一页',
                ));
//Controller
$model = new AutoSale;
$data = $model->getPageAutos(array('state'=>3),'id DESC', 0, 2);
$this->render('index',array(
   'autos'=>$data['autos'],
    'pages'=>$data['pages'],
     model'=>$model,
));
//Model
public function getPageAutos($terms, $order='id DESC', $page=0, $limit=8)
    {
        $criteria = new CDbCriteria;
        foreach($terms as $key=>$value)
        {
            $criteria->compare($key, $value);
        }
        $pages=new CPagination($this->count($criteria));
        $pages->pageSize=$limit;
        $pages->applyLimit($criteria); 
        $criteria->offset = $pages->currentPage*$pages->pageSize;
        $criteria->order = 'id DESC';
        $criteria->limit = $limit;
        return array(
            'autos'=>  $this->findAll($criteria),
            'pages'=>  $pages,
        );
    }

//View
$this->widget('CLinkPager', array(
                    'pages' => $pages,
                    'prevPageLabel' => '上一页',
                    'nextPageLabel' => '下一页',
                ));

留下评论

鄂ICP备13000209号-1

鄂公网安备 42050602000277号