寫此文是對本身的一種督促,也是對學習過程的一個記錄。 先說一下對YII的第一感受:封裝極好,好像使用很方便,工具插件不少,能夠很方便的開發一套mvc站點。 爲啥會有這樣的感受?是由於我以前接觸到的框架都是更貼近原生,代碼極簡,只保留核心模塊,大部分功能都要本身動手來寫。此前一直認爲php框架也就是解決了一些基本路由,數據庫處理和視圖生成的功能。學習Yii以後才發現,框架其實能夠作的很方便,代碼開發效率能夠更高,因而可知此前的本身仍是太井底之蛙了! 最後,附上本身瞭解到的一個小問題,並以此文爲開始,記錄本身的Yii學習之旅。php
使用Gii模塊,報403錯誤web
Forbidden (#403) You are not allowed to access this page. The above error occurred while the Web server was processing your request. Please contact us if you think this is a server error. Thank you.
若是出到以上的錯誤,請先確認你的配置是不是正確的。數據庫
if (YII_ENV_DEV) { // 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', ]; }
原始 的配置是這樣的,若是你的 使用的是本地的服務器的話也就是localhost,則不會存在問題。bootstrap
若是你使用的是遠程服務器或者本地虛擬機的話,就會出現以上的錯誤提示了 詳細分析得知,是Gii作了默認IP限定了 源代碼以下:數組
namespace yii\gii; use Yii; use yii\base\BootstrapInterface; use yii\web\ForbiddenHttpException; class Module extends \yii\base\Module implements BootstrapInterface { public $controllerNamespace = 'yii\gii\controllers'; public $allowedIPs = ['127.0.0.1', '::1']; 。。。。。。
源代碼作了限定了 只容許 127.0.0.1是能夠訪問的其餘都是不行的。php框架
因此解決以上的問題 須要修改配置以下:服務器
if (YII_ENV_DEV) { // 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', '192.168.*.*', '192.168.178.20'], ]; }
這樣在 allowedIPs 數組裏面的IP所有能夠訪問了mvc