支付宝赞助帐号:service@kuitao8.com 

Yii2 ListView显示数据

Created2015-07-31   Views 2048    Author 懒人程序
控制器
<?php

namespace app\controllers;

use yii\web\Controller;
use yii\data\ActiveDataProvider;
use app\models\ZsDynasty;

class TestController extends Controller
{
    public function actionIndex()
    {
        $query = ZsDynasty::find();
		$dataProvider = new ActiveDataProvider([
							'query' => $query,
							'pagination' => [
								'pageSize' => 15,
							],
						]);
		return $this->render('index', [
            'dataProvider' => $dataProvider
        ]);
    }
}

视图
view/test/index.php
<?php
use yii\helpers\Html;
use yii\widgets\ListView;

$this->title = '朝代';
$this->params['breadcrumbs'][] = $this->title;
?>
<h1>朝代</h1>
<ul>
<?php
echo ListView::widget([
	'dataProvider' => $dataProvider,
	'itemView' => '_item',//子视图
]);
?>
view/test/_item.php
<?php
use yii\helpers\Html;
use yii\helpers\HtmlPurifier;
?>
<div class="post">
    <strong><?= Html::encode($model->dyn_id) ?></strong>
    <a href="test/index/<?= $model->dyn_id ?>"><?= HtmlPurifier::process($model->dyn_name) ?> </a>   
</div>

listview 默认文字修改 \basic\vendor\yiisoft\yii2\widgets\BaseListView.php

上一篇: linux free 命令
下一篇: yii2连接数据库,db and controller and vi
支持键盘 ← →

邮件订阅

订阅我们的精彩内容