コード例 #1
0
 public function fetchTemplate($viewName, $return = false)
 {
     //模板文件路径(可自定义)
     //若有主题
     $prePath = '';
     if ($this->theme) {
         $prePath = $this->theme . '/';
     }
     $viewFile = APP_PATH . MODULE_NAME . '/view/' . $prePath . CONTROLLER_NAME . '/' . $viewName . '.html';
     //不存在,则抛出异常
     if (!is_file($viewFile)) {
         $this->error("template does't exists!!!\n" . $viewFile);
     }
     //编译后存放的路径
     $tplcachepath = __ROOT__ . 'data/tplcache/' . $this->theme . '-' . MODULE_NAME . '-' . CONTROLLER_NAME . '-' . ACTION_NAME . '-' . $viewName . '.tpl.php';
     //是否有布局模板
     $layoutpath = '';
     if ($return == false && $this->layout) {
         $layoutpath = APP_PATH . MODULE_NAME . '/view/' . $prePath . $this->layout . '.html';
     }
     //编译模版
     $template = new \Framework\Template();
     $viewfile = $template->display($viewFile, $tplcachepath, $layoutpath);
     return $viewfile;
 }