本文整理汇总了PHP中SPLoader::loadTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP SPLoader::loadTemplate方法的具体用法?PHP SPLoader::loadTemplate怎么用?PHP SPLoader::loadTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPLoader
的用法示例。
在下文中一共展示了SPLoader::loadTemplate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
public function display()
{
$template = SPLoader::loadTemplate($this->_tpl, 'php');
if ($template) {
include $template;
} else {
throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'php', false)));
}
}
示例2: display
/**
* @param string $out - output type
* @param array $functions - array with PHP function to register
* @throws SPException
* @return mixed|string
*/
public function display($out = 'html', $functions = array())
{
$class = SPLoader::loadClass('helpers.template');
$methods = get_class_methods($class);
if (count($methods)) {
foreach ($methods as $method) {
$functions[] = $class . '::' . $method;
}
}
/* standard function registered via the core ini file */
$stdFunctions = SPLoader::loadIniFile('etc.template_functions');
if (count($stdFunctions)) {
foreach ($stdFunctions as $class => $fns) {
if (strstr($class, '.')) {
$class = SPLoader::loadClass($class, false, 'sp-root');
}
if (count($fns)) {
foreach ($fns as $method => $state) {
if ($state) {
$functions[] = $class == 'functions' ? $method : $class . '::' . $method;
}
}
}
}
}
Sobi::Trigger('TemplateEngine', 'RegisterFunctions', array(&$functions));
$this->createXML();
if (SPRequest::cmd('xml') && Sobi::Cfg('debug.xml_raw', false) && (!Sobi::Cfg('debug.xml_ip', null) || Sobi::Cfg('debug.xml_ip') == SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'))) {
SPFactory::mainframe()->cleanBuffer();
echo $this->_xml->saveXML();
exit;
} elseif (SPRequest::cmd('xml')) {
Sobi::Error('Debug', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__);
}
$template = SPLoader::loadTemplate($this->_tpl, 'xsl');
if (!$template) {
$template = SPLoader::loadTemplate($this->_tpl, 'xslt');
}
if (Sobi::Cfg('cache.xml_enabled')) {
SPFactory::cache()->addView($this->_xml, $template, $this->_cacheData);
}
if ($template) {
try {
if (!($style = DOMDocument::load($template))) {
Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template), SPC::ERROR, 500, __LINE__, __FILE__);
}
} catch (DOMException $x) {
Sobi::Error('template', SPLang::e('CANNOT_LOAD_TEMPLATE_FILE', $template, $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
}
Sobi::Trigger('TemplateEngine', 'LoadStyle', array(&$style));
$processor = new XSLTProcessor();
$processor->setParameter('block', 'xmlns', 'http://www.w3.org/1999/xhtml');
$processor->registerPHPFunctions($functions);
SPException::catchErrors(SPC::WARNING);
try {
$processor->importStylesheet($style);
} catch (SPException $x) {
Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template) . $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
}
SPException::catchErrors(0);
if ($out == 'html') {
$doc = $processor->transformToDoc($this->_xml);
$doc->formatOutput = true;
return $this->cleanOut($doc->saveXML());
} else {
$doc = $processor->transformToDoc($this->_xml);
$doc->formatOutput = true;
return $doc->saveXML();
}
} else {
throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'xsl', false)));
}
}