查询生成器 $db = new \yii\db\Query();$users = $db->from('qh_user_member_view')->select('id,name')->where('id=:id',[':id'=>$id])->all();
active record 联表查询
userModel $this->hasOne 1对1 $this->hasMany 1对多
with leftjoin
$customer = UserModel::find()->select('id, username')->with('members')->asArray()->all(); $this->hasOne(MemberModel::className(), ['uid' => 'id'])->select('uid,sex,age');
inner join $customer = UserModel::find()->select('id, username')->innerJoinWith('members')->asArray()->all(); return $this->hasOne(MemberModel::className(), ['uid' => 'id'])->select('uid,sex,age');