Пример #1
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('news/category');
     if (!($news_category = Model_News_Category::find($id))) {
         Session::set_flash('error', 'Could not find news_category #' . $id);
         Response::redirect('news/category');
     }
     $val = Model_News_Category::validate('edit');
     if ($val->run()) {
         $news_category->name = Input::post('name');
         if ($news_category->save()) {
             Session::set_flash('success', 'Updated news_category #' . $id);
             Response::redirect('news/category');
         } else {
             Session::set_flash('error', 'Could not update news_category #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $news_category->name = $val->validated('name');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('news_category', $news_category, false);
     }
     $this->template->title = "News_categories";
     $this->template->content = View::forge('news/category/edit');
 }