Example #1
0
 public function action_edit()
 {
     $id = $this->request->param('id', null);
     if ($id) {
         $news = Model_News::find_by_id($id);
     } else {
         $news = new Model_News();
     }
     if ($this->request->is_post()) {
         $post = $this->cleaned_post();
         $news->update($post);
         $news->defunct = Model_News::DEFUNCT_NO;
         $news->importance = Model_News::TYPE_NORMAL;
         $news->content = $this->get_raw_post('content');
         if (isset($post['defunct'])) {
             $news->defunct = Model_News::DEFUNCT_YES;
         }
         if (isset($post['top'])) {
             $news->importance = Model_News::TYPE_TOP;
         }
         if (is_null($news->user_id)) {
             $news->user_id = $this->current_user->user_id;
         }
         if ($news->save()) {
             $this->redirect('/admin/news');
         } else {
             $this->flash_error(__('common.error'));
         }
     }
     $this->template_data['title'] = __('admin.news.edit.edit_news_:name', array(':name' => $news->title));
     $this->template_data['news'] = $news;
 }