public function action_news_edit($news_id = 0) { $this->template->title = __("Chỉnh sửa thông tin bài viết"); $this->template->section_title = __("Chỉnh sửa thông tin bài viết"); $data = array(); $news = News::BLL()->find($news_id); if (!$news) { Message::error('Bài viết không tồn tại!'); Request::instance()->redirect('admin/news/cat_index'); } if (Request::$method == "POST") { $cat_id = intval($_POST['category_id']); if ($cat_id < 1) { Message::error('Mục tin cho bài viết không tồn tại!'); Request::instance()->redirect('admin/news/cat_index'); } $cat = NewsCategory::BLL()->find($cat_id); if (!$cat) { Message::error('Mục tin cho bài viết không tồn tại!'); Request::instance()->redirect('admin/news/cat_index'); } $active = isset($_POST['active']); $post = $news->validate_update($_POST); if ($post->check()) { //die($news->id); $post = $post->as_array(); $news->title = $post['title']; $news->slug = $post['slug']; $news->summary = $post['summary']; $news->img_thumb = $post['img_thumb']; $news->content = $post['story_content']; $news->active = $active; $news->Category = $cat; $news->save(); Message::success('Thay đổi thông tin bài viết thành công!'); Request::instance()->redirect('admin/news/by_cat/' . $cat->id); } else { $data['errors'] = $post->errors('admin/news'); $_POST = $post->as_array(); } } //get category select list $categories = NewsCategory::BLL()->findAll()->toArray(); $select_cat = array(); foreach ($categories as $cat) { $select_cat[$cat['id']] = $cat['name']; } $data['select_cat'] = $select_cat; $data['news'] = $news->toArray(); $this->template->content = View::factory('admin/news/news_edit', $data); }