Ejemplo n.º 1
0
 public function action_edit($id = null)
 {
     if (Auth::has_access('country.edit') == false) {
         Session::set_flash("error", "Only admins may edit countries!");
         Response::redirect("country/") and die;
     }
     is_null($id) and Response::redirect('Country');
     $country = Model_Country::find($id);
     $val = Model_Country::validate('edit');
     if ($val->run()) {
         $country->name = Input::post('name');
         $country->iso_code = Input::post('iso_code');
         if ($country->save()) {
             Session::set_flash('success', 'Updated country #' . $id);
             Response::redirect('country');
         } else {
             Session::set_flash('error', 'Could not update country #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $country->name = $val->validated('name');
             $country->iso_code = $val->validated('iso_code');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('country', $country, false);
     }
     $this->template->title = "Countries";
     $this->template->content = View::forge('country/edit');
 }