yii 调试sql

  • 系统自带调试

    • 入口文件index.php开启调试模式

      1
      2
      3
      4
      5
      6
      7
      // remove the following lines when in production mode
      defined('YII_DEBUG') or define('YII_DEBUG',true);
      // specify how many levels of call stack should be shown in each log message
      //YII_TRACE_LEVEL的数字越大,信息越清楚
      defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
      //app use time
      //defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME',microtime(true));
    • 配置文件main.php配置如下

      1
      2
      3
      4
      5
      6
      7
      8
      9
      'log'=>array(
      'class'=>'CLogRouter',
      'routes'=>array(
      array(
      'class'=>'CFileLogRoute',
      'levels'=>'error, warning',
      ),
      ),
      ),
  • 调试工具

    • yii-debug-toolbar把包解压后放到extensions中,在配置文件main.php中添加CLogRouter

      1
      2
      3
      4
      5
      6
      7
      8
      9
      'log'=>array(
      'class'=>'CLogRouter',
      'routes'=>array(
      array(
      'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute',
      'ipFilters'=>array('127.0.0.1'),
      ),
      )
      ),
    • components中添加以下属性

      1
      2
      'enableProfiling'=>true,
      'enableParamLogging'=>true,