예제 #1
0
 public function actionKabupaten()
 {
     $id_prov = $_POST['depdrop_parents'][0];
     $selected = null;
     if (!empty($_POST['depdrop_params'])) {
         $selected = $_POST['depdrop_params'][0];
     }
     $model = Kabupaten::find()->where(['id_prov' => $id_prov])->all();
     $data = [];
     foreach ($model as $item) {
         $data[] = ['id' => $item->id_kab, 'name' => $item->nama];
     }
     echo Json::encode(['output' => $data, 'selected' => $selected]);
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Kabupaten::find();
     $query->joinWith(['provinsi']);
     $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;
     }
     $dataProvider->sort->defaultOrder = ['id_kab' => SORT_DESC];
     $dataProvider->sort->attributes['nama_provinsi'] = ['asc' => ['provinsi.nama' => SORT_ASC], 'desc' => ['provinsi.nama' => SORT_DESC]];
     $query->andFilterWhere(['like', 'kabupaten.id_kab', $this->id_kab])->andFilterWhere(['like', 'provinsi.nama', $this->nama_provinsi])->andFilterWhere(['like', 'kabupaten.nama', $this->nama]);
     return $dataProvider;
 }