/** * 获取模板文件路径. * $tplName 格式参见 display 方法说明. * * @access public * @param string $tplName 模板名称, 默认 NULL. * @return array ['tpl' => 模板文件路径, 'compile' => 模板编译文件路径] */ protected function fetchViewPath($tplName = NULL) { $isGroup = Url::isGroup(); $groupName = Url::groupName(); $controllerName = Url::controllerName(); $actionName = Url::actionName(); $style = ''; // 主题名称. // 临时主题目录名, 只能用一次 theme 方法, 但 theme 方法设置主题名的优先级低于冒号格式的设置. if (FALSE !== $this->_theme) { $style = $this->_theme; $this->_theme = FALSE; } // 判断 $tplName 已指定 主题名 的情况. $pos = NULL === $tplName ? FALSE : strpos($tplName, ':'); if (FALSE !== $pos) { list($style, $tplName) = explode(':', $tplName); } $style = empty($style) ? $this->style : $style; $style = empty($style) ? '' : $style . '/'; $result['tpl'] = $this->tplDir . $style; $result['compile'] = $this->compileDir . $style; $fullTpl = ''; // 解析模板名称. if (NULL === $tplName || empty($tplName)) { $fullTpl = ($isGroup ? $groupName . '/' : '') . $controllerName . '/' . $actionName; } else { $arrTpl = explode('/', $tplName); $tplLen = count($arrTpl); $fullTpl = $tplName; if ($isGroup && 1 === $tplLen) { $fullTpl = $groupName . '/' . $controllerName . '/' . $fullTpl; } elseif ($isGroup && 2 === $tplLen) { $fullTpl = $groupName . '/' . $fullTpl; } elseif (1 === $tplLen) { $fullTpl = $controllerName . '/' . $fullTpl; } elseif ($tplLen > ($isGroup ? 3 : 2)) { $arrTpl = array_slice($arrTpl, 0, $isGroup ? 3 : 2); $fullTpl = implode('/', $arrTpl); } } $pos = strrpos($fullTpl, '/'); $oriTplName = substr($fullTpl, $pos + 1); // 模板文件名. $oriTplPath = substr($fullTpl, 0, $pos); // 相对路径. $result['tpl'] .= $fullTpl . $this->tplSuffix; $result['compile'] .= $oriTplPath . '/' . md5($oriTplName) . '_' . $oriTplName . '.php'; return $result; }