天天看點

gii無法通路 yii2_yii2 學習曆程——gii配置外部使用者通路權限問題

今天嘗試在家裡連接配接公司外部伺服器的yii架構的gii功能,提示

Forbidden (#403)

You are not allowed to access this page.

于是花了較長的時間在百度和論壇上尋找yii2 外部pc端通路gii功能時的配置方法, 大多都是說需要找到main.php檔案,然後改變預設的ip通路位址(127.0.0.1)實作, 但是找了半天無果。 自己官網文檔找了好久解決方案如下:

在檔案vendor\yiisoft\yii2-gii\Module.php 中

public $allowedIPs = ['115.123.134.185(替換為你現在的電腦ip)', '::1'];

解決了一個小問題。

2016-07-13 更正: 本着不随意修改源碼的原則, 直接在配置檔案進行配置修改;

修改如下:

在config/main-local.php中加入:

'allowedIPs' => ['127.0.0.1', '::1','*'], // 這裡允許所有使用者加載gii

詳細如下:

if (!YII_ENV_TEST) {

// configuration adjustments for 'dev' environment

$config['bootstrap'][] = 'debug';

$config['modules']['debug'] = [

'class' => 'yii\debug\Module',

];

$config['bootstrap'][] = 'gii';

$config['modules']['gii'] = [

'class' => 'yii\gii\Module',

'allowedIPs' => ['127.0.0.1', '::1','*'], // 這裡允許所有使用者加載gii

];

}