Yii 2.0支持远程访问gii

时间:2014-12-05 00:21:05

标签: yii2

简单的问题,试图在yii 2中启用对gii的远程访问 - 文档说http://www.yiiframework.com/doc-2.0/guide-start-gii.html

Note: If you are accessing Gii from a machine other than localhost, the access will be denied by default for security purpose. You can configure Gii to add the allowed IP addresses as follows,

'gii' => [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'] // adjust this to your needs
],

事情是,它没有说明在哪里添加 - 猜猜配置/ web.php

但是在哪个部分?

1 个答案:

答案 0 :(得分:5)

您需要添加2个地方。

通常在你的main-local.php

中这样做
if (!YII_ENV_TEST) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];   
}

所以你需要在config的bootstrap部分和modules部分添加gii。这将基本上将它们从config / main.php附加到数组 返回[     ' ID' => ' APP-后端&#39 ;,     '基本路径' =>目录名(的 DIR ),     ' controllerNamespace' => '后端\控制器&#39 ;,     '自举' => ['登录&#39],     '模块' => [         ]     ],

在您提供的链接上,请查看上方。你应该这样做:

if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'] // adjust this to your needs
];
}