yii2的分页组件

  控制器


public function actionIndex(){
        $db = new Query;
        $count = $db->select('notice_id')->from('notice')->count(); // 查询需要分页的目的数据的总个数
        $newspagination = new \yii\data\Pagination(['totalCount'=>$count,'defaultPageSize' => 2]);
        $data = News::find()->orderBy('release_time DESC')->offset($newspagination->offset)->limit($newspagination->limit)->all(); 
        return $this->render('index',['data'=>$data,'newspagination'=>$newspagination]);
}



  视图

   

   

 <?php
      echo \yii\widgets\LinkPager::widget([
            'pagination'=>$newspagination,//分页类
            'options'=>['class'=>'page'],  //设置分页组件样式
            ]);
 ?>
     

          效果图如下:

yii2的分页组件_第1张图片

你可能感兴趣的:(分页,yii)