Yii学习笔记(三)
使用Gii生成代码
Gii 是 Yii 中的一个模块。
可以通过配置应用的 yii\base\Application::modules
属性开启它。
通常来讲在 config/web.php
文件中会有以下配置代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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', ]; } |
应用的入口脚本 web/index.php
, 将看到这行代码将 YII_ENV_DEV
设为 true
:
1 2 3 |
defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); |
访问gii功能的url是:http://hostname/index.php?r=gii
通过本机以外的机器访问 Gii,请求会被出于安全原因拒绝。 可以配置 Gii 为其添加允许访问的 IP 地址:
1 2 3 4 5 |
'gii' => [ 'class' => 'yii\gii\Module', 'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'] // 按需调整这里 ], |