如何在Yii2中允许使用适当的(指定的)IP地址访问模块?

时间:2016-08-07 22:06:54

标签: php yii2

如何允许在Yii2中使用适当的(指定的)IP地址访问模块?

我试试,但是给出错误:

Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: app\modules\getsp\getsp::allowedIPs

web.php

//....
'modules' => [
    'getsp' => [
        'class' => 'app\modules\getsp\getsp',
        'allowedIPs' => ['127.0.0.1', '::1'],
    ],                        
], 
 //...

1 个答案:

答案 0 :(得分:1)

尝试此解决方案可能会解决您的问题。

主-local.php

if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';

$config['bootstrap'][] = 'getsp';
$config['modules']['getsp'] = 'yii\getsp\Module';
}

Main.php

'modules' => [
    'getsp' => [
        'class' => 'yii\getsp\Module',
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.1.*', 'XXX.XXX.XXX.XXX'] // The server machine ip is ex:-(192.168.1.102). or your PC PC ip address ex:-(192.168.1.101) adjust this to your needs
    ],
],