public function action_edit() { $page_id = $this->request->param('id'); if (!$page_id) { throw new Exception('ID must be set!'); } $this->template->page_title = 'Edit page #' . $page_id; $view = View::factory('cp/pages/edit'); $page = new Model_Page(); $pages = $page->get_page_by_id($page_id); if (!$pages) { throw new Exception('Not found!'); } if ($this->request->method() === Request::POST) { if (!Security::check($this->request->post('csrf_token'))) { throw new HTTP_Exception_401("Bad token!"); } $post_title = $this->request->post('title'); $post_content = $this->request->post('content'); $data = array('title' => $post_title, 'content' => $post_content); $update_page = $page->update_page($data, $page_id); if (!$update_page) { throw new Exception('Check fields!'); } Session::instance()->set('Page.success', true); $this->request->redirect('cp/pages/edit/' . $page_id); } $view->pages = $pages; $view->success = Session::instance()->get_once('Page.success'); $this->template->content = $view->render(); }