小巫师 2017-06-09 09:06:03 945次浏览 0条评论 2 0 0

1、在view视图层列表展示页面
头部放置:

<?php
use yii\widgets\LinkPager;
?>

尾部放置:

<?= LinkPager::widget(['pagination' => $pages]); ?>

2、在控制器层

<?php

namespace backend\controllers;

use Yii;
use yii\web\Controller;
use frontend\models\Text;
use yii\data\Pagination;


class NewsController extends Controller
{
  public $enableCsrfValidation = false;
  public function actionIndex()
  {
    $count = News::find()->count();
    $page = new Pagination(['totalCount' => $count,'pageSize'=>'5']);
    $data = News::find()
      ->innerJoinWith('newstype')
      ->offset($page->offset)
      ->limit($page->limit)
      ->asArray()
      ->all();
    // print_r($data);die;
    return $this->render('index',['data'=>$data,'page'=>$page]);
  }

3、在model层建立text.php

<?php

namespace frontend\models;

use yii;
use yii\db\ActiveRecord;
class Text extends ActiveRecord{
    public static function tableName()
    {
        return '{{text}}';
    }
}
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册
在线
225