1.项目安装debug工具
php composer.phar require --prefer-dist yiisoft/yii2-debug
2.配置web/index.php
defined('yii_debug') or define('yii_debug', true);defined('yii_env') or define('yii_env', 'dev');
3.配置config/web.php
if(file_exists(__dir__ . "/web-local.php")) { $localconfig = require __dir__ . "/web-local.php"; $config = arrayhelper::merge($config, $localconfig);}
(相关教程推荐:yii框架)
4.增加web-local.php
<?php $localconfig = [ 'components' => [ 'log' => [ 'tracelevel' => yii_debug ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\filetarget', 'levels' => ['error', 'warning'], ], ], ], ],]; if (yii_env_dev) { // configuration adjustments for 'dev' environment $localconfig['bootstrap'][] = 'debug'; $localconfig['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', '::1'], 'allowedips' => ['*'], ]; $localconfig['bootstrap'][] = 'gii'; $localconfig['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', '::1'], ];} return $localconfig;
5.设置runtime目录为可读写
以上就是yii2怎么访问debug的详细内容。