Exemplo n.º 1
0
Arquivo: city.php Projeto: vano00/jobs
 public function action_edit($id = null)
 {
     is_null($id) and \Response::redirect('city');
     $city = \Model\City::find($id);
     if (\Input::method() == 'POST') {
         $val = \Model\City::validate('edit');
         if ($val->run()) {
             $city->name = \Input::post('name');
             $city->country_id = \Input::post('country_id');
             if ($city->save()) {
                 \Session::set_flash('success', 'Updated city #' . $id);
                 \Response::redirect('admin/city');
             } else {
                 \Session::set_flash('error', 'Could not update the city');
             }
         } else {
             \Session::set_flash('error', $val->error());
         }
     }
     $data['actions'] = ['back' => ['label' => 'Back', 'url' => 'admin/city']];
     $data['countries'] = \Model\Country::query()->get();
     $this->template->set_global('city', $city, false);
     $this->template->title = "Cities";
     $this->template->content = \View::forge('city/edit.twig', $data);
 }
Exemplo n.º 2
0
 public function action_delete($id = null)
 {
     if ($country = \Model\Country::find($id)) {
         $country->delete();
         \Session::set_flash('success', 'Deleted country #' . $id);
     } else {
         \Session::set_flash('error', 'Could not delete country #' . $id);
     }
     \Response::redirect('admin/country');
 }