예제 #1
0
파일: pages.php 프로젝트: reGative/Cosmoss
 public function action_create()
 {
     $this->template->page_title = 'Create Page';
     $user = new Model_User();
     $session = Session::instance()->get('user');
     $view = View::factory('cp/pages/create');
     $view->author = $user->get_user_by_session_id($session);
     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');
         $post_author = $this->request->post('author');
         $post_date = time();
         if (empty($post_title) && empty($post_content) && empty($post_author) && empty($post_date)) {
             throw new Exception('Please don`t make empty fields!');
         }
         $page = new Model_Page();
         $data = array('title' => $post_title, 'content' => $post_content, 'author' => $post_author, 'date' => $date);
         $insert_page = $page->insert_page($data);
         if (!$insert_page) {
             throw new Exception('Check if you are connected to database!');
         }
         $this->request->redirect('cp/pages');
     }
     $this->template->content = $view->render();
 }