public function action_new() { if (Auth::instance()->logged_in()) { $view = View::factory('topic/new'); $category = new Model_Category(); $category_id = $this->request->param('id'); $view->categories = $category->find_all(); $user_id = Auth::instance()->get_user()->pk(); $view->role_id = ORM::factory('Roles_User')->get_last_role_id($user_id); $user_id = Auth::instance()->get_user()->pk(); $users = ORM::factory('User')->get_data($user_id); $this->template->content = $view->render(); if ($this->request->method() === Request::POST) { if (!Security::check($this->request->param('id'))) { throw new Exception("Bad token!"); } $title = $this->request->post('title'); $category_id = $this->request->post('category_id'); $author = $user_id; $content = $this->request->post('content'); if (empty($title) or empty($category_id) or empty($author) or empty($content)) { throw new Exception("Fields cannot be empty!"); } $data = array('title' => $title, 'category_id' => $category_id, 'author_id' => $author, 'content' => $content, 'published' => time()); $topic = new Model_Topic(); $publish_topic = $topic->publish($data); if (!$publish_topic) { throw new Exception("Cannot publish your topic!"); } $this->request->redirect('category/index/' . $category_id); } } else { $this->redirect(''); } }