Exemplo n.º 1
0
 /**
  * Returns the content of
  * a rendered element
  *
  * @param  string $viewPath
  * @param  array  $config
  * @param  string $wrapper
  * @return string
  */
 public function render($viewPath, $config = array(), $wrapper = '')
 {
     $view = PathHelper::getRealViewPath(ltrim($viewPath, DR_SP), '', Template::getInstance()->getLayout()->getName());
     $path = $view;
     // Handle relative path
     if (!PathHelper::isAbsolute($viewPath)) {
         $backtrace = debug_backtrace();
         $viewIndex = PathHelper::getFirstViewIndexFromDebugBacktrace($backtrace);
         if (false === $viewIndex) {
             throw new Exception\NoViewOriginFoundException('The view "' . $view . '" could not be
                 include. You can render relative path\'s
                 only from an other view.');
         }
         $file = PathHelper::normalizePath($backtrace[$viewIndex]['file']);
         $dir = pathinfo($file, PATHINFO_DIRNAME);
         $path = PathHelper::getRealViewFile(PathHelper::normalizePath($dir . DR_SP . $viewPath));
         $view = PathHelper::normalizePath(realpath($path));
         if ($view == $file) {
             throw new Exception\RenderRecursionException('The view "' . $view . '" is including itself (Recursion).');
             exit;
         }
     }
     /**
      * Default check & render
      */
     if (!$view || !file_exists($view)) {
         if (!$view) {
             $view = $path;
         }
         throw new Exception\ViewIncludeNotFoundException('The view "' . $view . '" was not found
             and could not be included');
     }
     $content = $this->getRenderedHtml($view, $config);
     if (!empty($wrapper)) {
         $content = sprintf($wrapper, $content);
     }
     return $content;
 }
Exemplo n.º 2
0
 /**
  * Sets the view path
  *
  * @param string $view
  */
 public function setPath($view)
 {
     $layout = Template::getInstance()->getLayout()->getName();
     $viewFile = PathHelper::getRealViewPath($view, $this->getAction(), $layout);
     $this->pathView = $view;
     $this->path = $viewFile;
 }