写此文是对本身的一种督促,也是对学习过程的一个记录。 先说一下对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