gy-doc-code
[ class tree: gy-doc-code ] [ index: gy-doc-code ] [ all elements ]

Source for file Template.php

Documentation is available at Template.php

  1. <?php
  2.  
  3. namespace Gy\Core\Component\Mvc;
  4.  
  5. use Gy\Core\Lang;
  6.  
  7. if (!defined("GY_CORE") && (GY_CORE !== true)) die( "gy: err include core" );
  8.  
  9. class Template
  10. {
  11.     public $templateUrl; // ссылка на шаблон
  12.     // public $name; // имя шаблона
  13.     public $lang;
  14.     private $urlFileStyle; // url на файл со стилями, для этого шаблона
  15.     private $urlFileJs; // url для файла с js, для этого шаблона
  16.     
  17.     public function __construct($url, $lang)
  18.     {
  19.         $this->templateUrl = $url.'/template.php';
  20.  
  21.         // проверить существует ли файл стилей для компонента
  22.         if (file_exists($url.'/style.css')) {
  23.             $this->urlFileStyle = $url.'/style.css';
  24.         }
  25.  
  26.         // если есть файл js
  27.         if (file_exists($url.'/script.js')) {
  28.             $this->urlFileJs = $url.'/script.js';
  29.         }
  30.  
  31.         $this->lang = new Lang($url, 'template', $lang);
  32.     }
  33.  
  34.     /* show - нарисовать/показать шаблон 
  35.     *    arr - массив с данными для шаблона
  36.     */
  37.     /*public function show($arr){
  38.         $arRes = $arr;
  39.         include $this->template_url;
  40.         // TODO как то по красивее сделать
  41.     }*/
  42.  
  43.     /** 
  44.      * show - нарисовать/показать шаблон
  45.      * @param $arRes - массив с данными для шаблона // array for template
  46.      * 
  47.      * @return void - ничего не вернёт, подключится файл шаблона // include template
  48.      */
  49.     public function show($arRes, $arParam)
  50.     {
  51.  
  52.         // если есть стили то добавить стили
  53.         if (!empty($this->urlFileStyle)) {
  54.             echo '<style>';
  55.             include $this->urlFileStyle;
  56.             echo '</style>';
  57.         }
  58.  
  59.         // файл шаблона
  60.         include $this->templateUrl;
  61.  
  62.         // если есть js то добавить его
  63.         if (!empty($this->urlFileJs)) {
  64.             echo '<script>';
  65.             include $this->urlFileJs;
  66.             echo '</script>';
  67.         }
  68.     }
  69. }

Documentation generated on Sat, 27 Apr 2024 11:17:30 +0300 by phpDocumentor 1.4.3