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

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 production
defined('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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bomb_2002

有所帮助就好

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值