/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Mtprovinces::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); $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->joinWith('provinceCountry'); $query->andFilterWhere(['province_id' => $this->province_id, 'province_created' => $this->province_created, 'province_updated' => $this->province_updated]); $query->andFilterWhere(['like', 'province_name', $this->province_name])->andFilterWhere(['like', 'province_status', $this->province_status])->andFilterWhere(['like', 'mtcountries.country_name', $this->province_country_id]); $query->groupBy(['province_country_id', 'province_id']); $query->orderBy(['province_country_id' => 'ASC', 'province_name' => 'ASC']); return $dataProvider; }
<?php $form = ActiveForm::begin(['options' => ['class' => 'form-horizontal'], 'fieldConfig' => ['template' => '{label}<div class="col-sm-10">{input}<div class="help-block">{error}</div></div>', 'labelOptions' => ['class' => 'col-sm-2 control-label']]]); ?> <div class="box-body mt-cities-create"> <?php echo $form->errorSummary($model); ?> <?php echo $form->field($model, 'city_country_id')->dropDownList(ArrayHelper::map(Mtcountries::find()->all(), 'country_id', 'country_name'), ['prompt' => 'Select Country', 'onchange' => '$.post("/admin/configurations/regional/provinces/list?id=' . '"+$(this).val(),function(data){ $("select#mtcities-city_province_id").html(data); });'])->label('Country'); ?> <?php echo $form->field($model, 'city_province_id')->dropDownList(ArrayHelper::map(Mtprovinces::find()->all(), 'province_id', 'province_name'), ['prompt' => 'Select Province'])->label('Province'); ?> <?php echo $form->field($model, 'city_name')->textInput(['maxlength' => true]); ?> <div class="box-footer"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success pull-right' : 'btn btn-primary pull-right']); ?> <?php echo Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']); ?> </div> <?php
/** * @return \yii\db\ActiveQuery */ public function getMtprovinces() { return $this->hasMany(Mtprovinces::className(), ['province_country_id' => 'country_id']); }
/** * @return \yii\db\ActiveQuery */ public function getCityProvince() { return $this->hasOne(Mtprovinces::className(), ['province_id' => 'city_province_id']); }
/** * Finds the Mtprovinces model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Mtprovinces the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Mtprovinces::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }