/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Department::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', 'department', $this->department]); return $dataProvider; }
use backend\modules\setting\models\Department; /* @var $this yii\web\View */ /* @var $searchModel backend\modules\personal\models\PersonalSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'บุคลากร'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="personal-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('เพิ่มบุคลากร', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'user.username', ['format' => 'html', 'attribute' => 'department_id', 'value' => function ($model) { return $model->department->department; }, 'filter' => Html::activeDropDownList($searchModel, 'department_id', ArrayHelper::map(Department::find()->all(), 'id', 'department'), ['class' => 'form-control', 'prompt' => 'เลือกสังกัด'])], 'firstname', 'lastname', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
?> <?php echo $form->field($user, 'username'); ?> <?php echo $form->field($user, 'password_hash'); ?> <?php echo $form->field($user, 'email'); ?> <?php echo $form->field($model, 'department_id')->dropDownList(ArrayHelper::map(Department::find()->all(), 'id', 'department')); ?> <?php echo $form->field($model, 'firstname')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'lastname')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'address')->textarea(['rows' => 6]); ?> <?php