熊本污 2016-05-03 15:02:05 3665次浏览 2条评论 2 0 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]);?>

您需要登录后才可以评论。登录 | 立即注册