Yii框架使用yiidebugtb调试并输出SQL语句
为了获得更美观且不干扰页面其他元素的调试体验,推荐使用yiidebugtb工具进行调试。
首先下载yiidebugtb组件,并将其放置到application.extensions.yiidebugtb目录下。
接下来需要修改配置文件main.php,添加相应的日志路由代码。
复制代码 代码如下: 'log'=>array( 'class'=>'CLogRouter', 'routes'=>array( array( 'class'=>'CFileLogRoute', 'levels'=>'error, warning,trace', ),
// 以下是新加 array( // configuration for the toolbar 'class'=>'XWebDebugRouter', 'config'=>'alignLeft, opaque, runInDebug, fixedPos, collapsed, yamlStyle', 'levels'=>'error, warning, trace, profile, info', //'categories' => 'system.db.*', 'allowedIPs'=>array('127.0.0.1','::1','192\.168\.1[0-5]\.[0-9]{3}','如果程序在外网需要填入你的公网的ip'), ), ), )
此外,还需对数据库连接配置部分进行相应调整。
复制代码 代码如下: 'db'=>array( 'connectionString'=>'mysql:host=*.*.*.*;dbname=test', 'emulatePrepare'=>true, // 加入 'enableParamLogging' => true, // 加入 'username'=>'-----', 'password'=>'---', 'charset'=>'utf8', 'schemaCachingDuration'=>'0', 'autoConnect'=>false, ),
完成上述步骤后,配置即告结束。
效果示例如下:
