Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2. class controller_Index extends _Controller
  3. {
  4.     protected $layout;
  5.     protected $model;
  6.     protected $modelUser;
  7.    
  8.     function __construct()
  9.     {
  10.         $this->layout = new _View('layout/index.phtml');
  11.         $this->model = new model_Article;
  12.         $this->modelUser = new model_User;
  13.         $this->modelNews = new model_News;
  14.         $this->layout->user = $this->modelUser->getCurrentUser();
  15.        
  16.         $data = $this->model->getItems();
  17.         $this->layout->menu = $data;
  18.  
  19.     }
  20.    
  21.     function login()
  22.     {
  23.         if (isset($_POST['login']) && isset($_POST['password']))
  24.         {
  25.             $user = $this->modelUser->login($_POST);
  26.             if (isset($user[0])) return $this->index();
  27.         }
  28.         $this->layout->main = new _View('login.phtml');
  29.         return $this->layout;
  30.     }
  31.    
  32.     function logout()
  33.     {
  34.         $this->modelUser->logout();
  35.         return $this->index();
  36.     }
  37.    
  38.     function index()
  39.     {
  40.         $view = new _View('index.phtml');
  41.         $view->data = $this->model->getItems();
  42.         $news = $this->modelNews->getNews();
  43.         $view ->news = $news;
  44.         $this->layout->main = $view;
  45.         return $this->layout;
  46.     }
  47.    
  48.     function news()
  49.     {  
  50.         if (empty($_GET['id'])) self::http404();
  51.         $data = $this->modelNews->getOneNews(array('id' => $_GET['id']));
  52.         if (empty($data[0])) self::http404();
  53.         self::$config['title'][] = $data[0]->title;
  54.         $view = new _View('news.phtml');
  55.         $view->data = $data;
  56.         $this->layout->main = $view;
  57.         return $this->layout;
  58.     }
  59.    
  60.     function article()
  61.     {
  62.         if (empty($_GET['id'])) self::http404();
  63.         $data = $this->model->getItem(array('id' => $_GET['id']));
  64.         $menu = $this->model->getItems();
  65.         if (empty($data[0])) self::http404();
  66.         self::$config['title'][] = $data[0]->title;
  67.         $view = new _View('article.phtml');
  68.         $view->data = $data;
  69.          $view->menu = $menu;
  70.         $this->layout->main = $view;
  71.         return $this->layout;
  72.     }
  73. }
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement