本文整理汇总了PHP中MVCUtils::getTemplateModule方法的典型用法代码示例。如果您正苦于以下问题:PHP MVCUtils::getTemplateModule方法的具体用法?PHP MVCUtils::getTemplateModule怎么用?PHP MVCUtils::getTemplateModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MVCUtils
的用法示例。
在下文中一共展示了MVCUtils::getTemplateModule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findTemplate
/**
* Find a template
*
* This will look in the module for the specified template to try and find
* a path to the template. If it cannot be found, each module will be
* serched for the file. The the full path to the requested template will
* be returned.
*
* @param mixed $template Either a template ID or file name
* @return string The full path to the template including the file name, or false if not found
*/
public static function findTemplate($template)
{
//Make sure $template is a name, not id
if (is_numeric($template)) {
$template = self::getTemplateFileName($template);
}
$fullPath = false;
//Check for windows and unix-type full path
if (stristr('[A-Z]:', $template) !== false) {
$fullPath = true;
} else {
if (substr($template, 0, 1) == '/') {
$fullPath = true;
}
}
if ($fullPath && file_exists($template)) {
return $template;
}
static $cache = array();
global $cfg;
//Check for cached result
if (isset($cache[$template])) {
return $cache[$template];
//if cached, execution stops here
}
//Get the module in which the template reisdes
$module = MVCUtils::getTemplateModule($template);
//If the template was found in the database then look for it in the
//module specified in the database.
if (!is_null($module)) {
//Generate the path of the template file
$path = $cfg['general']['toolkitRoot'] . "/{$module}/templates/{$template}";
$path = realpath($path);
//Check the template exists where it should
if (!file_exists($path)) {
BasicLogger::logMessage("Template '{$template}' could not be found. I was looking here: {$path}", self::module, 'error');
return false;
}
//Cache the return value
$cache[$template] = $path;
return $path;
//If the template was not found in the database then start searching
//each modules template directory. The is because templates can
//request to include a file which is not in the database. This could
//be more efficiet if there was some method of knowing the directory
//of the parent template, because only that directory would then need
//to be searched
} else {
foreach ($cfg['modules'] as $module) {
$path = $cfg['general']['toolkitRoot'] . '/' . $module . '/templates/';
//Convert relative paths to full paths
$path = realpath($path);
if (strlen($path) > 0) {
//Recursively search the directory
$path = self::findFile($path, $template);
if ($path !== false) {
//cache the return value
$cache[$template] = $path;
return $path;
}
}
}
return false;
}
/*
//If execution has got this far then the file has not been found
BasicLogger::logMessage("Template '$template' could not be found", self::module, 'error');
return false;*/
}