yii相关配置

1、如何在页面下边显示SQL的查询时间?

key:在log 组件的routes 中加入
array(
    'class'=>'CProfileLogRoute',
    'levels'=>'error,warning',
)

同时在db 组件中加入
'enableProfiling'=>true,
在这种情况下,可以调用CDbConnection::getStats() 查看执行了多少个语句,并用了多少时间。

2、如何知道某一个程序段执行需要的时间?
key:配置好CProfileLogRoute 后,在需要测试的地方加上
Yii::beginProfile('blockID');
//程序段
Yii::endProfile('blockID');


3、如何在页面底部显示所有的db 相关的日志?
key:同时,在log 组件的routes中加入
array(
    'class'=>'CWebLogRoute',
    'levels'=>'trace,info,error,warning',
    'categories'=>'system.db.*',
    //'showInFireBug'=>true, //将在firebug中显示日志
);

把日志记录到数据库
array(
    'class'=>'CDbLogRoute',
    'logTableName'=>'applog',
    'connectionID'=>'db',
);
运行时表applog 会自动生成,不过不能生成,参照api自己建立

log 配置中的level 设置不对,可能会得不到日志信息,另外level,category 的值可以随便写,
只要在用yii::Log("","自定义level","自定义的category") 时对应起来即可;

4、如何记录$_GET ,$_SESSION 等信息?
key: 在以上的routes 中各个配置中加上 'filter'=>'CLogFilter',

5、如何记录更详细的信息,能记录statck 吗?
key:在入口文件中加上 define('YII_TRACE_LEVEL',10); 数字越大,记录的越详细

6、如果在调试时,终止程序运行且看到日志,不能用die 及exit;
用 application::end,即Yii::app()->end() ,其会触发 onEndRequest 事件,日志就是在这个事件中记录的。


7、如何发布一个资源文件并引用?
key:$css=Yii::app()->getAssetManager()->publish(dirname(__FILE__)."/others.css");
    Yii::app()->clientScript->registerCssFile($css);


8、activeRecord 几个占位方法重写的注意点:
key: 必须带boolean 返回值


9、如何改变activeable 中默认的标题?
key: 重写方法 attributeLabels

10、过滤不良代码?
key:
$purifier=new CHtmlPurifier;
$purifier->options=array("HTML.Allowed"=>"div");
$content=$purifier->purify($content);

或者

<?php $this->beginWidget('CHtmlPurifier'); ?>
...display user-entered content here...
<?php $this->endWidget(); ?>

引用:http://blog.sina.com.cn/s/blog_7d85d15a0101fxhi.html

原文地址:https://www.cnblogs.com/gramblog/p/11206195.html