예제 #1
0
 public function actionLoaddistrict($id = null)
 {
     //$id คือ รหัส pk ของจังหวัด
     $districts = District::find()->where(['province_id' => $id])->orderBy('district_name')->all();
     $option = '<option value="">-กรุณาเลือกอำเภอ-</option>';
     foreach ($districts as $d) {
         $option .= '<option value="' . $d->id . '">' . $d->district_name . '</option>';
     }
     echo $option;
 }
예제 #2
0
 public function actionFind()
 {
     $searchForm = new FindForm();
     $view['districtList'] = ArrayHelper::map(District::find()->where("district != ''")->orderBy('district')->all(), 'id_district', 'district');
     $params = ArrayHelper::merge(Yii::$app->request->getQueryParams(), Yii::$app->request->post());
     $searchForm->load($params);
     if (implode('', $searchForm->toArray())) {
         //$view['list'] = $searchForm->search();
     } else {
         $amount = (int) ArrayHelper::getValue(Main::findBySql("select count(id_person) as amount from main")->asArray()->one(), 'amount');
     }
     $view['pagination'] = new Pagination(['pageSize' => 10]);
     //dd($amount);
     $dataProvider = new ActiveDataProvider(['query' => $searchForm->getSearchQuery(), 'totalCount' => $amount ? $amount : null, 'pagination' => $view['pagination']]);
     //dd($dataProvider);
     $view['dataProvider'] = $dataProvider;
     $view['searchForm'] = $searchForm;
     return $this->render('find', $view);
 }
예제 #3
0
 protected function getDistrict($id)
 {
     $datas = District::find()->where(['AMPHUR_ID' => $id])->all();
     return $this->MapData($datas, 'DISTRICT_ID', 'DISTRICT_NAME');
 }
예제 #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @return \Illuminate\Http\Response
  */
 public function postDestroy()
 {
     if ($this->request->ajax()) {
         $id = $this->request['id'] ?: '';
         $data = District::find($id);
         if ($data) {
             $data->delete();
         }
         $response = array('url' => route('place.index'));
         return $response;
     }
 }
예제 #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $value = District::find($id);
     if ($value == null) {
         return response(['errorMessage' => 'Not Found'], 404);
     }
     $value->delete();
     return response('', 200);
 }
예제 #6
0
/* @var $this yii\web\View */
/* @var $model app\models\Contact */
/* @var $form yii\widgets\ActiveForm */
if($model->isNewRecord){
    $province = [];
    $district = [];
    $tambon = [];
    
    $district_list = [];
    $tambon_list = [];
}else{
    $province = $model->tambon->province_id;
    $district = $model->tambon->district_id;
    $tambon = $model->tambon_id;
    
    $district_list = ArrayHelper::map(District::find()
            ->where(['province_id'=>$province])->all(), 'id', 'district_name');
    $tambon_list = ArrayHelper::map(Tambon::find()
            ->where(['district_id'=>$district])->all(), 'id', 'tambon_name');
}

?>

<div class="contact-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'firstname')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'lastname')->textInput(['maxlength' => true]) ?>
예제 #7
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response*/
 public function destroy($id)
 {
     $district = District::find($id);
     if ($district) {
         $district->delete();
         Session::flash('success', Lang::get('ruban.district.deleted'));
         return Redirect::route('ruban.districts.index');
     } else {
         Session::flash('danger', Lang::get('ruban.district.notfound'));
         return Redirect::route('ruban.districts.index');
     }
 }
예제 #8
0
 /**
  * Get the list wards by ditrict id
  *
  * @param \Illuminate\Http\Request $request
  * @param int                      $id
  *
  * @return JSON
  */
 public function ajaxGetWardByCityId(Request $request, $id)
 {
     //Only accept AJAX request with GET method
     if ($request->ajax() && $request->isMethod('GET')) {
         if (District::find((int) $id) === null) {
             return pong(0, _t('opp'), 404);
         }
         $wards = $this->_getWardsByCityId($id);
         return pong(1, ['data' => $wards->toArray()]);
     }
 }