/** * Отрисовать по шаблону * @param String $template * @param array $date * @return String */ public function fetch($template, $data = false) { // найти шаблон, он может быть и у любого потомка этого класса, они же и друг от друга наследуют $dir = $this->dir; $class = get_class($this); while (!file_exists($dir . '/' . $template) && !file_exists($template)) { $class = get_parent_class($class); if ($class) { $ref = new ReflectionClass($class); if (!$ref->isAbstract()) { $obj = new $class(); $dir = $obj->getDir(); } } else { return ''; } } // Если переданы данные, сделать обозначения if ($data !== false) { foreach ($data as $key => $value) { Output::assign($key, $value); } } $templatedir = Output::getTemplateCompiler()->getTemplateDir(); Output::getTemplateCompiler()->setTemplateDir($dir); $content = Output::fetch($template); Output::getTemplateCompiler()->setTemplateDir($templatedir); return $content; }
/** * Отрработать вывод по шаблону * @param string $template * @return string */ public function fetch($template) { /* TODO: тут проблемы с отрисовкой, нужно наследовать шаблоны */ if ($_SERVER[debug][report]) { profiler::add("Выполнение", "{$this->name}: {$template} начало отрисовки"); } // найдем шаблон $obj = $this; while ($obj) { if (file_exists($obj->getViewDir() . '/' . $template)) { $templatedir = Output::getTemplateCompiler()->getTemplateDir(); Output::getTemplateCompiler()->setTemplateDir($obj->getViewDir()); $content = Output::fetch($template); Output::getTemplateCompiler()->setTemplateDir($templatedir); break; } $parentclass = get_parent_class($obj); if ($parentclass) { $obj = new $parentclass(); } else { $obj = false; } } if ($_SERVER[debug][report]) { profiler::add("Выполнение", "{$this->name}: {$template} конец отрисовки"); } return $content; }