Beispiel #1
0
 /**
  * define page title and load template files
  */
 public function index()
 {
     $action = $_GET['action'];
     // var_dump($_GET['action']);
     $this->data['title'] = 'All Pages';
     $page = new \models\pages();
     $pagecategory = new \models\pagecategory();
     if (isset($_POST) && !empty($_POST)) {
         $pagename = $_POST['pagename'];
         $category = $_POST['category'];
         $sort_order = $_POST['sort_order'];
         $slug = \helpers\url::generateSafeSlug($pagename);
         $insert_array = array('pagename' => $pagename, 'categoryid' => $category, 'sort_order' => $sort_order, 'page_alias' => $slug);
         $insert_id = $page->create($insert_array);
         if ($insert_id > 0) {
             $message = 'ok';
         } else {
             $message = 'no';
         }
     }
     if (isset($action) && !empty($action)) {
         switch ($action) {
             case 'delete':
                 $where_array = array('id' => $_GET['id']);
                 $delete = $page->delete($where_array);
                 if ($delete > 0) {
                     $message = 'ok';
                 } else {
                     $message = 'no';
                 }
                 break;
             default:
                 # code...
                 break;
         }
     }
     if ($message == 'ok') {
         $this->data['success'] = 'Record Added!';
     } else {
         if ($message == 'no') {
             $this->data['error'] = 'Operation Fails!';
         }
     }
     $this->data['pages'] = $page->allPages();
     $this->data['page_categories'] = $pagecategory->all();
     View::rendertemplate('home_header', $this->data);
     View::rendertemplate('sidebar', $this->data);
     View::render('pages/pages.index', $this->data);
     View::rendertemplate('footer', $this->data);
 }
Beispiel #2
0
 private function default_vars()
 {
     $curPageFull = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $curPage = explode("?", $curPageFull);
     $cfg = $this->f3->get('cfg');
     unset($cfg['DB']);
     $this->vars['_isLocal'] = isLocal();
     $this->vars['_version'] = $this->f3->get('_version');
     $this->vars['_v'] = $this->f3->get('_v');
     $this->vars['_cfg'] = $cfg;
     $this->vars['_folder'] = $this->vars['folder'];
     $this->vars['_domain'] = "http://" . $_SERVER['HTTP_HOST'];
     $this->vars['_user'] = $this->f3->get('user');
     $this->vars['_isAjax'] = is_ajax();
     $pageContent = models\pages::getInstance()->getAll();
     $p = array();
     foreach ($pageContent as $item) {
         $p[$item['ID']] = $item['content'];
     }
     $this->vars['_page_content'] = $p;
     $this->vars['_categories'] = models\categories::format($this->f3->get('categories'), true);
     $this->vars['_itemCount'] = $this->f3->get('itemCount');
     //test_array($categories);
 }