记录日志
Yii::log($content);
debug模式下,记录日志出现warning
修改config/web.php中的 $config['modules']['debug'] ,增加'allowedIPs' => ['127.0.0.1', ...]
使用自定义的过滤器
- 在components下新建一个过滤器,继承于yii\base\ActionFilter
<?php
namespace app\components;
use Yii;
use yii\base\ActionFilter;
class ActionTimeFilter extends ActionFilter
{
private $_startTime;
public function beforeAction($action)
{
$this->_startTime = microtime(true);
return parent::beforeAction($action);
}
public function afterAction($action, $result)
{
$time = microtime(true) - $this->_startTime;
Yii::info("Action '{$action->uniqueId}' spent $time second.");
return parent::afterAction($action, $result);
}
}
- 在contoller中使用自定义的过滤器
use app\components\ActionTimeFilter;
class YhlController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => ActionTimeFilter::className(),
'only' => ['say-msg'],
],
];
}
...