模型
<?php
namespace backend\models;
use Yii;
use yii\db\ActiveRecord;
class Users extends ActiveRecord{
public static function tableName(){
return 'users';
}
}
?>
控制器
<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\data\Pagination;
use backend\models\Users as UsersModel;
class UsersController extends Controller{
public $layout="mains";
public function actionIndex(){
$usermodel=new UsersModel();
$list = $usermodel::find()->orderBy('creatertime DESC');
$page = new Pagination(['totalCount' => $list->count(), 'pageSize' => 1]);
$model = $list->limit($page->limit)->offset($page->offset)->asArray()->all();
return $this->render('index',[
'model'=>$model,
'pagination'=>$page
]);
}
public function actionAdd(){
return $this->render('add',[
]);
}
}
?>
视图
<?php
use yii\widgets\LinkPager;
?>
<?=
LinkPager::widget([
'pagination' => $pagination,
'nextPageLabel' => '',
'prevPageLabel' => '',
'maxButtonCount' => 5,
'options' => ['class' => 'chen-pagination'],//自定义class
]);
?>