Example #1
0
 /**
  * Finds the Role model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Role the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Role::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
 /**
  * @return array Return an array of role names from the Role model
  */
 public function getRoles()
 {
     $query = Role::find()->select('name');
     $array = [];
     foreach ($query->all() as $record) {
         $array[] = $record['name'];
     }
     return $array;
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Role::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #4
0
<div class="<?php 
echo $model->formName();
?>
-form">

    <?php 
$form = ActiveForm::begin(['id' => $model->formName(), 'options' => ['class' => 'modalSubmit'], 'enableAjaxValidation' => false, 'enableClientValidation' => true]);
?>

    <?php 
Portlet::begin(['id' => $model->formName() . '-form-portlet', 'title' => $this->title, 'buttons' => [Html::submitButton('<i class="fa fa-check"></i> <u>U</u>pdate', ['class' => 'btn green-haze btn-circle', 'value' => "form#{$model->formName()}", 'accesskey' => 'u'])]]);
?>

    <?php 
echo Html::activeHiddenInput($model, 'user_id');
?>

    <?php 
echo $form->field($model, 'role_id')->widget(Select2::classname(), ['data' => Role::getSelect2Data(), 'options' => ['placeholder' => 'Select a role ...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
Portlet::end();
?>

    <?php 
ActiveForm::end();
?>

</div>
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRole()
 {
     return $this->hasOne(Role::className(), ['id' => 'role_id']);
 }