/** * Show a form for adding a new page * @throws \Exception */ public function add_page() { $this->to_tpl['success'] = false; $this->to_tpl['id'] = 0; $this->to_tpl['title'] = ""; $this->to_tpl['errors'] = false; $this->template = "admin/add-page"; if (isset($_POST['submit'])) { $errors = $this->check_input(); if (is_array($errors) && !empty($errors)) { $this->to_tpl['errors'] = $errors; } else { $page = new Page(); $page->title_sr = post_string('title_sr'); $page->body_sr = post_string('body_sr'); $page->title_en = post_string('title_en'); $page->body_en = post_string('body_en'); $page->permalink_sr = $page->check_permalink(generate_permalink($page->title_sr), "sr"); $page->permalink_en = $page->check_permalink(generate_permalink($page->title_en), "en"); $page->date_created = new \DateTime("now"); $page->published = post_bool('published'); if ($id = $page->saveToDb()) { $this->to_tpl['success'] = true; $this->to_tpl['id'] = $id; $this->to_tpl['title'] = $page->title_sr; $_POST = array(); } } } return; }