Guest User

/classes/View.php

a guest
Oct 23rd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. <?php
  2.     include_once 'D:\USR\apache\htdocs\s2.localhost\Phoenix_demo\classes\Model.php';
  3.    
  4.    
  5.     class View 
  6.     {
  7.         /**
  8.          * Path to document root (absolute)
  9.          */
  10.         private $DOC_ROOT;
  11.        
  12.         /**
  13.          * @var class Model
  14.          */
  15.         private $model;
  16.        
  17.         /**
  18.          *Path to templates' dir (absolute)
  19.          *
  20.          * @var string
  21.          */
  22.         private $templateDir = '';
  23.        
  24.         /**
  25.          *
  26.          * @param class_Model $model
  27.          * @param string $doc_root Path to document root (absolute) of web server
  28.          * @param string $templateDir Path to templates' dir (absolute)
  29.          */
  30.         public function __construct(Model $model, $doc_root, $templateDir)
  31.         {
  32.             $this->DOC_ROOT = $doc_root;
  33.             $this->model = $model;
  34.             $this->templateDir = $templateDir;
  35.         }
  36.        
  37.         /**
  38.          * Возвращает текст нужной страницы.
  39.          * @param string $page
  40.          * @return string Текст страницы
  41.          */
  42.         public function output($page)
  43.         {
  44.             ob_start();
  45.             switch ($page) {
  46.                 case 'main':
  47.                     //объявляем и заполняем переменные, которые затем нужны будут в шаблоне
  48.                     $header = $this->DOC_ROOT . '/Phoenix_demo/Private/tpl_header.php';
  49.                     $color_on = $this->model->getColor();
  50.                     $changes = $this->model->getChanges();
  51.                     $tpl_changes = $this->templateDir . '/tpl_changes.php';
  52.                     $citations = $this->model->getQuotes();
  53.                     $count = $this->model->getNumOfQuotes();
  54.                     $tpl_citations = $this->templateDir . '/tpl_citations.php';
  55.                     //вызывает общий шаблон страницы, который использует $tpl
  56.                     include $this->templateDir . 'tpl_main.php';
  57.                     break;
  58.                 default:
  59.                     break;
  60.             }
  61.             return ob_get_clean();         
  62.         }
  63.        
  64.         /**
  65.          * Отсылает указанную страницу пользователю.
  66.          * @param string $page
  67.          */
  68.         public function render($page)
  69.         {
  70.             $contents = $this->output($page);
  71.             echo $contents;
  72.         }
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment