|-转 yii2如何开启debug并在底部显示工具栏(Yii2基础版basic和Yii2高级版advanced)
//增加用来线上显示工具栏 20180203
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
// 配置访问IP地址 183.30.221.127
'allowedIPs' => ['127.0.0.1', '::1', '183.30.220.106'],
],
],
在配置文件里的模块里这样配置加加入自己的ip,就可以显示debug工具栏
web/index.php代码不用管。
开启debug
1、 在web/index.php文件中添加下面两行代码:
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
2、在Yii2基础版(yii2-app-basic)中
打开yii config目录下的web.php文件,找到如下配置
if (YII_ENV_DEV) {   
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [        'class' => 'yii\debug\Module',
    // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '我的IP'],  
    ];
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [        
    'class' => 'yii\gii\Module',        
    // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '我的IP'],
    ];
}
把自己的IP添加进去即可开启debug。
如果只改web/index.php里的YII_DEBUG的设置,没有在配置文件web.php里把自己的IP添加到allowedIPs里则无法开启debug,如果把'allowedIPs' => ['127.0.0.1', '我的IP'],直接注释掉,则没有IP限制,debug也就开启了。
在Yii2 高级版(yii2-app-advacned)中,找到common/main.php,在modules的debug里配置,把自己的IP添加进去即可。
return [
    'name' => '测试',
    'language' => 'zh-CN',
    'timeZone' => 'Asia/Shanghai',
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
    ],
    'modules' => [
        //增加用来显示工具栏  ,加入访问的ip地址
        'debug' => [
            'class' => 'yii\debug\Module',
             // 配置访问IP地址 
            'allowedIPs' => ['127.0.0.1', '::1','113.83.***.***'],
        ],
    ],
];
这时运行页面如果报错就会显示具体的错误信息。 ...
浏览更多内容请先登录。
            立即注册
			
			更新于:2023-02-04 19:26:00
			
					相关内容
Yii2 报错代码整理
Yii2 HeadersAlreadySentException 报错
Yii2报错 Object configuration must be an array containing a "class" o...
查问我看笔记功能的实现过程-全文搜索待开启,试试yiisoft/yii2-sphinx
yii2框架中使用sphinx使用搜索引擎 多条件选择搜索
运行php composer.phar require --prefer-dist yiisoft/yii2-sphinx
Yii2模型简介
Yii2模型简介-属性
Yii2模型简介-场景
Yii2模型简介-验证规则
Yii2模型简介-块赋值
Yii2模型简介-非安全属性
Yii2模型简介-数据导出
Yii2模型简介-字段
Yii2模型简介-最佳实践
Yii2小部件Widget
Yii2的扩展整理
【坑,勿用】Yii的yii-xunsearch扩展,支持中文的搜索引擎,支持全文索引全...
简单,易用的yii2导入和导出组件( illusion/yii2-excel)
最完整的安装教程-Yii Gridview小部件之kartik-v/yii2-grid扩展的安装和使...
推荐内容