加油努力,

yii2中gii外网访问的配置方法

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

 

posted @ 2015-05-14 18:47  活着挺好  阅读(1567)  评论(0编辑  收藏  举报

我是郎