分页示例代码 [ 2.0 版本 ]
//控制器
use Yii;
use frontend\models\Country;
use yii\web\Controller;
use yii\data\Pagination;//加载分页类
// 显示列表
	public function actionList(){
		$user = new Country();
		$user_count = $user->find()->count();
		$data['pages'] = new Pagination(['totalCount' => $user_count]);
		// 设置每页显示多少条
		$data['pages']->defaultPageSize = 2;
		$user_list = $user->find()->offset($data['pages']->offset)->limit($data['pages']->limit)->asArray()->all();
		$data['pages']->params=array("tab"=>'all');
		//print_r($data['pages']);die;
		return $this->render('show',[
			'arr' => $user_list,
			'pages' => $data['pages'],
		]);
	}
//视图
<?php
	use yii\helpers\Html;
	use yii\widgets\LinkPager; //使用小物件
?>
<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
<table border="1">
<tr>
	<th>ID</th>
	<th>NAME</th>
</tr>
<?php foreach ($arr as $key => $v): ?>
<tr>
	<td><?php echo $v['id'] ?></td>
	<td><?php echo $v['name'] ?></td>
</tr>
<?php endforeach ?>
</table>
<?php echo LinkPager::widget(['pagination' => $pages]);?>
熊本污 天下熊熊一般污
            注册时间:2016-05-03
最后登录:2016-09-21
在线时长:6小时36分
    最后登录:2016-09-21
在线时长:6小时36分
- 粉丝8
- 金钱615
- 威望140
- 积分2075

共 2 条评论
我想发666
我只想说6666
~( ̄▽ ̄~)(~ ̄▽ ̄)~