/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UserModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { $query->where('1=0'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/* @var $model app\models\master\U2Branch */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="u2-branch-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'branch_id')->dropDownList(\backend\models\master\Branch::selectOptions(), ['style' => 'width:60%;'])->label('Branch'); ?> <?php $data = User::find()->select(['username as value', 'username as label', 'id as id'])->asArray()->all(); echo AutoComplete::widget(['model' => $model, 'attribute' => 'user_name', 'options' => ['class' => 'form-control'], 'clientOptions' => ['source' => $data, 'autoFill' => true, 'minLength' => '1', 'select' => new JsExpression("function( event, ui ) {\n \$('#u2branch-user_id').val(ui.item.id);\n }"), 'search' => new JsExpression("function( event, ui ) {\n \$('#u2branch-user_id').val('');\n }")]]); ?> <?php echo $form->field($model, 'user_id')->hiddenInput()->label(false); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end();