public function actionTest(){$model=Categoryregion::find()->where(['parent'=>0]);echo $model->createCommand()->sql;}
这是一个快速提示转储SQL以进行查询。
$query = new Books::find()->where('author=2');
echo $query->createCommand()->sql;
或者要获取包含所有参数的SQL,请尝试:
$query->createCommand()->getRawSql()
感谢http://chris-backhouse.com/Yii2-Output-the-SQL-from-a-query-builder/1027