/** * Renders a view with a layout. * @param string $layout name of the view to be rendered. * @param array $placeholders list placeholders. * @param string $defaultPathLayout * @param bool $isAjax * @return string the rendering result. Null if the rendering result is not required. * @throws \Exception */ public function render($layout, array $placeholders = [], $defaultPathLayout = '@views', $isAjax = false) { $layout = FileHelper::normalizePath(Alias::getAlias($layout)); if (!strstr($layout, DS)) { $class = explode('\\', get_class($this)); $layout = Alias::getAlias($defaultPathLayout) . DS . 'layouts' . DS . strtolower(str_replace('Controller', '', array_pop($class))) . DS . $layout; } return $this->getTemplate()->render($layout, $placeholders, $this, $isAjax); }
/** * Normalize path. * @param string $path * @return string * @throws TemplateException * @throws \Exception */ protected function normalizePath($path) { $path = Alias::getAlias($path, ['lang' => $this->locale]); $path = FileHelper::normalizePath($path, DIRECTORY_SEPARATOR, false); if (!pathinfo($path, PATHINFO_EXTENSION)) { $path .= '.' . $this->defaultExtension; } $normalizePath = $path; // relative path if ((strpos($normalizePath, DIRECTORY_SEPARATOR) === false || strpos($normalizePath, '.' . DIRECTORY_SEPARATOR) !== false) && $this->path) { $normalizePath = dirname($this->path) . DIRECTORY_SEPARATOR . $normalizePath; $normalizePath = realpath($normalizePath); } if (!file_exists($normalizePath)) { throw new TemplateException(TemplateException::UNKNOWN_FILE, ['path' => $path]); } return $normalizePath; }