/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Distrito::find(); // 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([ 'idDistrito' => $this->idDistrito, ]);*/ $query->andFilterWhere(['like', 'nome', $this->nome]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getRelIdDistrito() { return $this->hasOne(Distrito::className(), ['idDistrito' => 'idDistrito']); }
/** * Finds the Distrito model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Distrito the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Distrito::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
$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(); ?> </div>