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; }
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); }
protected function getDistrict($id) { $datas = District::find()->where(['AMPHUR_ID' => $id])->all(); return $this->MapData($datas, 'DISTRICT_ID', 'DISTRICT_NAME'); }
/** * 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; } }
/** * 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); }
/* @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]) ?>
/** * 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'); } }
/** * 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()]); } }