public function actionLists($id) { $countPosts = Kota::find()->where(['PROVINCE_ID' => $id])->count(); $posts = Kota::find()->where(['PROVINCE_ID' => $id])->all(); if ($countPosts > 0) { foreach ($posts as $post) { echo "<option value='" . $post->CITY_ID . "'>" . $post->CITY_NAME . "</option>"; } } else { echo "<option>-</option>"; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Kota::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(['CITY_ID' => $this->CITY_ID, 'POSTAL_CODE' => $this->POSTAL_CODE]); $query->andFilterWhere(['like', 'PROVINCE_ID', $this->PROVINCE_ID])->andFilterWhere(['like', 'PROVINCE', $this->PROVINCE])->andFilterWhere(['like', 'TYPE', $this->TYPE])->andFilterWhere(['like', 'CITY_NAME', $this->CITY_NAME]); return $dataProvider; }
/** * Finds the Kota model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Kota the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Kota::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo "<h2><b>Destination</b></h2>"; ?> <?php $Expired = Provinsi::find()->all(); $listData = ArrayHelper::map($Expired, 'PROVINCE_ID', 'PROVINCE'); echo $form->field($model, 'DES_PROVINCE')->dropDownList($listData, ['prompt' => '-Pilih Provinsi-', 'onchange' => ' $.post( "index.php?r=site/lists&id=' . '"+$(this).val(), function( data ) { $( "select#harga-des_city" ).html( data ); }); '])->label('Des Province'); ?> <?php $dataPost = ArrayHelper::map(Kota::find()->all(), 'CITY_ID', 'CITY_NAME'); echo $form->field($model, 'DES_CITY')->dropDownList($dataPost); ?> <?php echo $form->field($model, 'HARGA')->textInput(); ?> <?php echo $form->field($model, 'KATEGORI')->dropDownList(['DOKUMENT' => 'DOKUMENT', 'FILE' => 'FILE', 'BARANG' => 'BARANG'], ['prompt' => '-Pilih Kategori-'], ['label' => 'soni']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
public function actionSubcat() { $out = []; if (isset($_POST['depdrop_parents'])) { $parents = $_POST['depdrop_parents']; if ($parents != null) { $cat_id = $parents[0]; $model = Kota::find()->asArray()->where(['province_id' => $cat_id])->all(); //$out = self::getSubCatList($cat_id); // the getSubCatList function will query the database based on the // cat_id and return an array like below: // [ // ['id'=>'<sub-cat-id-1>', 'name'=>'<sub-cat-name1>'], // ['id'=>'<sub-cat_id_2>', 'name'=>'<sub-cat-name2>'] // ] foreach ($model as $key => $value) { $out[] = ['id' => $value['province_id'], 'name' => $value['city_name']]; } echo json_encode(['output' => $out, 'selected' => '']); return; } } echo Json::encode(['output' => '', 'selected' => '']); }