我想用Yii 2写这样的sql:
select id, 1 as type from user;
这是我的代码:
$query = User::find()->select(['id', '1 as type'])->all();
1是常数,而不是用户的字段
解决方法:
要在查询的某些部分禁用引用和转义,请将其包装在yii\db\Expression中:
use yii\db\Expression;
...
$query = User::find()->select(['id', new Expresssion('1 as type')])->all();