php传递参数到函数内部
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = ''; $this->params['breadcrumbs'][] = $this->title; $allShopClass = \app\models\ShopClass::find()->all(); ?> <div class="sentiment-comment-goods-list-index"> <h1><?= Html::encode($this->title) ?></h1> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'title', 'data_id', 'url:url', 'shop_id', // 'shop_class_id', [ 'attribute' => 'shop_class_id', 'value' => function($data) use($allShopClass) { foreach ($allShopClass as $e) { if ($e->id == $data->shop_class_id) { return $e->name; } } }, ], ], ]); ?> </div>
use($allShopClass)