/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MunicipalCity::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(['municipality_id' => $this->municipality_id, 'province_id' => $this->province_id]); $query->andFilterWhere(['like', 'municipality_name', $this->municipality_name]); return $dataProvider; }
/* @var $form yii\widgets\ActiveForm */ ?> <div class="district-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'district_name')->textInput(['maxlength' => true]); ?> <?php $municipalcity = MunicipalCity::find()->all(); $listData = ArrayHelper::map($municipalcity, 'municipality_id', 'municipality_name'); echo $form->field($model, 'municipality_id')->dropDownList($listData, ['prompt' => 'Select your Municipal/City']); ?> <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(); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getMunicipalCities() { return $this->hasMany(MunicipalCity::className(), ['province_id' => 'province_id']); }
/** * @return \yii\db\ActiveQuery */ public function getMunicipality() { return $this->hasOne(MunicipalCity::className(), ['municipality_id' => 'municipality_id']); }
/** * Finds the MunicipalCity model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MunicipalCity the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MunicipalCity::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }