Heim > Artikel > Backend-Entwicklung > yii 2.0 GridView-自定义按钮跟链接
yii 2.0 GridView-自定义按钮和链接
直接贴代码吧:
= GridView::<span style="color: #000000;">widget([ </span>'dataProvider' => <span style="color: #800080;">$dataProvider</span>, <span style="color: #008000;">//</span><span style="color: #008000;">'filterModel' => $searchModel,</span> 'columns' =><span style="color: #000000;"> [ [</span>'class' => 'yii\grid\SerialColumn'], <span style="color: #008000;">//</span><span style="color: #008000;">显示的字段 //code的值</span> ['attribute'=>'这是测试code','value'=><span style="color: #0000ff;">function</span>(){<span style="color: #0000ff;">return</span> 'abc';}], 'name', 'population',<span style="color: #000000;"> [</span>'class' => 'yii\grid\ActionColumn','header' => '操作',],<span style="color: #000000;"> [ </span>'label'=>'更多操作', 'format'=>'raw', 'value' => <span style="color: #0000ff;">function</span>(<span style="color: #800080;">$data</span><span style="color: #000000;">){ </span><span style="color: #800080;">$url</span> = "http://www.baidu.com"<span style="color: #000000;">; </span><span style="color: #0000ff;">return</span> Html::a('添加权限组', <span style="color: #800080;">$url</span>, ['title' => '审核'<span style="color: #000000;">]); } ] ]</span>,<span style="color: #000000;"> ]); </span>?>
效果如图: