是实际开发中,有这么一个场景,Gridview 怎么访问外部变量,
use
在value
可调用函数中的函数签名后插入:
[ 'header' => "操作", 'class' => 'yii\grid\ActionColumn', 'template'=> '{ajax-edit}', 'buttons' => [ 'ajax-edit' => function ($url, $model, $key) use($package){ return Html::a('关联项目', ['ajax-generate-add', 'id' => $model->id,'package_id' => $package->id], [ 'class' => 'orange', 'data-toggle' => 'modal', 'data-target' => '#ajaxModal', ]) . '<br>'; }, ], ]