if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],
];
}
看來多讀英文網站還是很有好處的
我配置檔案寫錯位置了
In basic application template configuration structure is a bit different so Gii should be configured in config/web.php:
basic模版中配置結構有一點不同
是以應如上寫
那麼問題來了,basic例子中這麼寫是個特例,正常是如何?
============
自定義ActionColumn
= GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//顯示的字段
//code的值
['attribute'=>'這是測試code','value'=>function(){return 'abc';}],
'name',
'population',
['class' => 'yii\grid\ActionColumn','header' => '操作',],
[
'label'=>'更多操作',
'format'=>'raw',
'value' => function($data){
$url = "http://www.baidu.com";
return Html::a('添權重限組', $url, ['title' => '稽核']);
}
]
],
]); ?>
運作效果如下圖所示:
希望本文所述對大家基于Yii架構的PHP程式設計有所幫助。
模闆中url
$url=['books/index'];//yii2實際生成的網址
//http://115.29.37.34/advanced/backend/web/index.php?r=books/index
另外
$url = 'books/index';//yii2實際生成的網址
//http://115.29.37.34/advanced/backend/web/books/index
是以,在自定義ActionColumn的時候要注意這種寫法
自定義列
自定義列的寫法22 = gridview::widget([23 'dataprovider' => $dataprovider,
24 'filtermodel' => $searchmodel,
25 'columns' =>[26 ['class' => 'yii\grid\serialcolumn'],
27
28 'id',
29 'exam_name',
30
31 ['class' => 'yii\grid\actioncolumn','header' => '操作'],
32[33 'label' => '更多操作',
34 'format' => 'raw',
35 'value' => function($data){36 $url=[lbooks/index';
37 return html::a('添加科目',$url,
38 ['title' => '稽核']
39 );
40 }
41 ]
42 ],
43 ]); ?>