/** * 表关联 */ public function getUserGroup() { //管理员与其组,是一对一的关系 return $this->hasOne(UserGroup::className(), ['id' => 'user_group_id'])->select(['name']); }
/** * Finds the UserGroup model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return UserGroup the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UserGroup::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo $form->field($model, 'realname', ['inputOptions' => ['placeholder' => $model->getAttributeLabel('realname')]])->textInput(); ?> <?php echo $form->field($model, 'email', ['inputOptions' => ['placeholder' => $model->getAttributeLabel('email')]])->input('email'); ?> <?php echo $form->field($model, 'password', ['inputOptions' => ['placeholder' => $model->getAttributeLabel('password')]])->passwordInput(); ?> <?php echo $form->field($model, 'user_group_id')->label(Yii::t('user', 'User Group'))->dropDownList(ArrayHelper::map(UserGroup::find()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'role_name')->label(Yii::t('user', 'Role'))->dropDownList(ArrayHelper::map(Yii::$app->getAuthManager()->getRoles(), 'name', 'description')); ?> <?php echo $form->field($model, 'status')->checkbox(['value' => true]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('common', 'Create') : Yii::t('common', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>