/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Concelho::find(); $query->joinWith('relIdDistrito'); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['idConcelho' => $this->idConcelho]); $query->andFilterWhere(['like', 'Concelho.nome', $this->nome])->andFilterWhere(['like', 'Distrito.nome', $this->idDistrito]); return $dataProvider; }
<div class="cod-postal-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'codigo')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'localidade')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'idConcelho')->dropDownList(ArrayHelper::map(Concelho::find()->all(), 'idConcelho', 'nome'), ['prompt' => 'Escolher Concelho']); ?> <?php echo $form->field($model, 'idDistrito')->dropDownList(ArrayHelper::map(Distrito::find()->all(), 'idDistrito', 'nome'), ['prompt' => 'Escolher Distrito']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Criar' : 'Atualizar', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>