文章出處

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程序設計有所幫助。

這里有教程http://www.jb51.net/article/58531.htm

Yii中使用PHPExcel導出Excel的方法

模板中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     ]); ?>

 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()