嗯,是关联查询profile表
User.php:
public function getProfile()
{
return $this->hasOne(Profile::className(),['userid'=>'userid']);
}
UserController.php:
public function actionUsers()
{
$this->layout = "layout1";
$model = User::find()->joinWith('profile');
$count = $model->count();
$pageSize = Yii::$app->params['pageSize']['user'];
$pager = new Pagination(['totalCount'=>$count,'pageSize'=>$pageSize]);
$users = $model->offset($pager->offset)->limit($pager->limit)->all();
return $this->render("users",['users'=>$users,'pager'=>$pager]);
}
打印了结果集,能够查询到profile的数据