【笔记】Yii2 - Gii使用:配置

来源:互联网 发布:淘宝退款诈骗怎么解决 编辑:程序博客网 时间:2024/04/29 08:48

Yii2提供的工具有6个:Model Generator, CRUD Generator,Controller Generator,Form Generator,Module Generator,Extension Generator。如下图所示。

在浏览器地址输入:http://hostname/index.php?r=gii,即可看到下面的页面。


在yii项目的config文件夹中,配置Gii的相关信息内容如下:

$config = [...];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', ];}return $config;
Gii的配置在YII_ENV_DEV的判断中,是以模块的方式使用。YII_ENV_DEV表示当前项目环境是开发状态下才能使用。

配置YII_ENV_DEV为true,也就是开发环境的方式是在项目的入口文件中/web/index.php,可以看到开发环境的配置:

// comment out the following two lines when deployed to productiondefined('YII_DEBUG') or define('YII_DEBUG', true);defined('YII_ENV') or define('YII_ENV', 'dev');require(__DIR__ . '/../vendor/autoload.php');require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');$config = require(__DIR__ . '/../config/web.php');(new yii\web\Application($config))->run();
代码中,第一行为配置debug模式为true,也就是开启debug模式,第二行即为开启当前环境为开发环境。

在config配置中,如果不添加allowedIPs的属性,系统默认的是['127.0.0.1', '::1‘],表示Gii只能在本地环境使用。

yii\gii\Module

class Module extends \yii\base\Module implements BootstrapInterface{    /**     * @inheritdoc     */    public $controllerNamespace = 'yii\gii\controllers';    /**     * @var array the list of IPs that are allowed to access this module.     * Each array element represents a single IP filter which can be either an IP address     * or an address with wildcard (e.g. 192.168.0.*) to represent a network segment.     * The default value is `['127.0.0.1', '::1']`, which means the module can only be accessed     * by localhost.     */    public $allowedIPs = ['127.0.0.1', '::1'];
如果在远程使用,则要配置相关可访问IP,如下所示:

  $config['modules']['gii'] = [    'class' => 'yii\gii\Module',    'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*'],  ];



0 0
原创粉丝点击