示例#1
0
 public function update_weather()
 {
     if (!$this->is_ajax(false)) {
         return show_error("It's not Ajax request!<br/>Please confirm your program again.");
     }
     $id = $this->input_post('id');
     $lat = $this->input_post('lat');
     $lng = $this->input_post('lng');
     if (!($id && $lat && $lng && ($weather = Weather::find_by_id($id)))) {
         return $this->output_json(array('status' => false));
     }
     $weather->latitude = $lat;
     $weather->longitude = $lng;
     if (!$weather->save()) {
         return $this->output_json(array('status' => false));
     }
     return $this->output_json(array('status' => true));
 }
示例#2
0
 public function update($id = 0)
 {
     if (!($weather = Weather::find_by_id($id))) {
         return redirect(array('admin', 'weathers'));
     }
     if (!$this->has_post()) {
         return redirect(array('admin', 'weathers', 'edit', $weather->id));
     }
     $title = trim($this->input_post('title'));
     $latitude = trim($this->input_post('latitude'));
     $longitude = trim($this->input_post('longitude'));
     if (!($title && $latitude && $longitude)) {
         return identity()->set_session('_flash_message', '填寫資訊有少!', true)->set_session('title', $title, true)->set_session('latitude', $latitude, true)->set_session('longitude', $longitude, true) && redirect(array('admin', 'weathers', 'edit', $weather->id), 'refresh');
     }
     $weather->title = $title;
     $weather->latitude = $latitude;
     $weather->longitude = $longitude;
     if (!$weather->save()) {
         return identity()->set_session('_flash_message', '修改失敗!', true)->set_session('title', $title, true)->set_session('latitude', $latitude, true)->set_session('longitude', $longitude, true) && redirect(array('admin', 'weathers', 'edit', $weather->id), 'refresh');
     }
     return identity()->set_session('_flash_message', '修改成功!', true) && redirect(array('admin', 'weathers'), 'refresh');
 }