/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UserRole::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['role_id' => $this->role_id]); $query->andFilterWhere(['like', 'role_name', $this->role_name]); return $dataProvider; }
public function getUser_role() { return $this->hasOne(UserRole::className(), ['role_id' => 'role']); }
/** * Finds the UserRole model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UserRole the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UserRole::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'username')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'email')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'role')->dropDownList(ArrayHelper::map(UserRole::find()->all(), 'role_id', 'role_desc')); ?> <?php echo $form->field($model, 'status')->textInput(); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php