$query = User::find()
->where(['id'=>[1,2,3,4])
->select(['username'])
// get the AR raw sql in YII2
$commandQuery = clone $query;
echo $commandQuery->createCommand()->getRawSql();
$users = $query->all();
参考:https://gist.github.com/dcb9/e5fd296ba4bca16bf98c
如果这篇文章对您有帮助,不妨微信小额赞助我一下,让我有动力继续写出高质量的教程。