控制器:
$query=LinkType::find()->select('t2.id,t2.name,t2.url,t2.status,t2.created_at,t2.updated_at,t1.type_name,t1.type_state')
->leftJoin('gzb_friendly_link t2','t1.type_id=t2.type')
->from('gzb_link_type t1')
->where(['t1.type_cate'=>0,'t1.type_state'=>1,'t1.type_parentid'=>0]);
$countQuery = clone $query;
//实例化分页类
$pagination=new Pagination(['totalCount' => $countQuery->count()]);
//每页条数
$pagination->setPageSize(10);
//执行分页
$data= $countQuery->offset($pagination->offset)->limit($pagination->limit)->asArray()->all();
return $this->render('index',['datas'=>$data,'count'=>count($data),'pages'=>$pagination]);
视图:
<?php foreach ($datas as $key => $value):?>
......
<?php endforeach;?>
<div class="row">
<div class="col-sm-3" style="line-height: 567%">
<div class="summary">本页共<b><?php echo $count;?></b>条数据.</div>
</div>
<div class="col-sm-9">
<div class="dataTables_paginate paging_simple_numbers">
<?= LinkPager::widget([
'firstPageLabel' => '首页',
'lastPageLabel' => '尾页',
'maxButtonCount' => 5,
'nextPageLabel' => '下一页',
'prevPageLabel' => '上一页',
'hideOnSinglePage' => false,
/*'options' => ['id' => 'm-pagination'],*/
'pagination' => $pages
]); ?>
</div>
</div>
</div>