/**
  * Creates a new Area model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new Area();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['title' => "Create new Area", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['forceReload' => '#crud-datatable-pjax', 'title' => "Create new Area", 'content' => '<span class="text-success">Create Area success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
             } else {
                 return ['title' => "Create new Area", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
 public function store(array $input)
 {
     $area = new Area();
     $area->fill($input);
     $area->save();
     return $area;
 }
 /**
  * Creates a new Area model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Area();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $areas = [["อำเภอเมือง", 19.1664466, 99.90198880000001, 9], ["อำเภอแม่ใจ", 19.375557200000003, 99.79017810000001, 9], ["อำเภอดอกคำใต้", 19.150464, 100.0359661, 9], ["อำเภอภูกามยาว", 19.318769400000008, 99.96886360000001, 9], ["อำเภอภูซาง", 19.625313999999975, 100.3722477, 9], ["อำเภอเชียงคำ", 19.498743700000006, 100.3251564, 9], ["อำเภอเชียงม่วน", 18.947594699999996, 100.3048897, 9], ["อำเภอจุน", 19.427696400000016, 100.12551639999998, 9], ["อำเภอปง", 19.149037399999983, 100.2745494, 9]];
     foreach ($areas as $area) {
         $a = new Area();
         $a->name_th = $area[0];
         $a->lat = $area[1];
         $a->lon = $area[2];
         $a->zoom = $area[3];
         $a->save();
     }
 }
Exemple #5
0
 public function postIndex()
 {
     try {
         $area = new Area();
         $area->nombre = Request::input('nombre');
         $area->alias = Request::input('alias');
         $area->orden = Request::input('orden');
         $area->save();
         return $area;
     } catch (Exception $e) {
         return $e;
     }
 }