controller
use yii\data\Pagination;引入分页
public function actionShow(){
$query = regists::find();//model层
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(),"pageSize"=>2]);
$models = $query->offset($pages->offset)
->limit($pages->limit)
->all();
return $this->render('show', [
'models' => $models,
'pages' => $pages,
]);
model层
<?php
namespace app\models;
use Yii;
use yii\db\ActiveRecord;
class regists extends ActiveRecord{
public $verifyCode;
public static function tableName(){
return 'regist';
}
展示页面
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
//use yii\captcha\Captcha;
$this->title = '展示';
use yii\widgets\LinkPager;
?>
<center>
<table border=1>
<tr>
<td>ID</td>
<td>姓名</td>
<td>密码</td>
<td>性别</td>
<td>爱好</td>
<td>简介</td>
</tr>
<?php foreach($models as $v) { ?>
<tr>
<td><?php echo $v->id;?></td>
<td><?php echo $v->name;?></td>
<td><?php echo $v->pwd;?></td>
<td><?php echo $v->sex;?></td>
<td><?php echo $v->hoddy;?></td>
<td><?php echo $v->content;?></td>
</tr>
<?php } ?>
</table>
<?php echo LinkPager::widget([
'pagination' => $pages,
]); ?>
</center>