示例#1
0
文件: View.php 项目: kevinwan/xf
 /**
  * 渲染模板
  * @access public
  * @param string $template_file Action模板文件
  * @param string $cache_sign 缓存标识
  * @param XF_View_Layout_Abstract $layout 
  * @return string
  */
 public function render($template_file = null, $cache_sign = '', XF_View_Layout_Abstract $layout = null)
 {
     $this->getTemplateStartLocation();
     $request = XF_Controller_Request_Http::getInstance();
     $appName = $request->getModule();
     $controllerName = $request->getController();
     $actionName = $request->getAction();
     //如果没有设置模板,则自动获取当前Action名称相关的模板
     if ($template_file == null) {
         $template_file = $this->_template_folder . '/' . $controllerName . '/' . $actionName . '.php';
     }
     if (!is_file($template_file)) {
         throw new XF_View_Exception('Action template not found');
     }
     $content = $this->obGetContents($template_file);
     XF_Controller_Plugin_Manage::getInstance()->postRender($content);
     //是否需要缓存?
     if ($this->_cache_time > 0) {
         $layout_tag = '';
         if ($layout != null) {
             $layout_tag = '<!--Layout:' . get_class($layout) . ',' . $layout->getCacheTime() . ',' . (int) $layout->getCacheType() . '-->';
         }
         $_content = $content . $layout_tag . $this->_makeCacheHeadTitleAndHeadMeta();
         //写入缓存
         if ($this->_cache_instance instanceof XF_Cache_SECache) {
             XF_File::mkdirs(TEMP_PATH . '/Cache');
             $this->_cache_instance->setCacheSaveFile(TEMP_PATH . '/Cache/ActionViewCache');
         }
         $this->_cache_instance->setCacheTime($this->_cache_time);
         $this->_cache_instance->add($cache_sign, $_content);
     }
     //是否启用布局
     if ($layout != null) {
         $layout->assign('$layoutContent', $content);
         $content = $layout->render();
     }
     return $content;
 }