方法中写法:
<?php
use yiidataPagination;
// 分页显示
public function actionPage(){
$request=Yii::$app->request;
$get=$request->post();
// var_dump($get);
$user=new User;
$data = $user->find(); //这写要显示的数据
$pages = new Pagination(['totalCount' =>$data->count(),'pageSize'=>'1']); //实例化分页类,带上参数(总条数,每页显示条数)
$model = $data->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('page',[
'm'=>$model,
'pages' => $pages,
]);
}
view视图中的调用:
<?php
use yiiwidgetsLinkPager;
?>
foreach($model as $key=>$val)
{
这里就是遍历数据了,省略......
}
<?= LinkPager::widget(['pagination' => $pages]); ?>