1.新增公共配置文件(common/config/main-local.php)
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'logFile' => '@runtime/logs/info.log',
'levels' => ['info'],
//'categories' => ['application'],
],
],
],
2.公共数据模型文件中使用
public static function findByMatchList($product_id, $district_id)
{
$query = Clerk::find()
->joinWith(['clerkItems items'], true, 'INNER JOIN')
->where(['LIKE', 'items.product_ids', ','.$product_id.',']);
if($district_id > 0)
{
$query->joinWith(['clerkArea area'], true, 'INNER JOIN')
->andWhere(['area.district_id' => $district_id]);
}
$list = $query->all();
Yii::getLogger()->log('findByMatchList, $product_id:'.$product_id.'$product_id:'
.$district_id.', data:'.serialize($list).'sql:'.$query->createCommand()->rawSql, Logger::LEVEL_INFO);
return $list;
}