我正在尝试重新定位模板index.php我正在构建并获得重定向循环。我错过了什么吗?我试图做的是根据条目URL以及某些模板样式重定向默认页面。我的模板代码看起来像这样......
的config.php
<?php
//joomla configuration
JLoader::import('joomla.filesystem.file');
JHtml::_('behavior.framework', true);
JHtml::_('jquery.framework');
$app = JFactory::getApplication();
$config = JFactory::getConfig();
$doc = JFactory::getDocument();
//load template style sheets and scripts
$doc->addStyleSheet($this->baseurl.'/media/jui/css/bootstrap.min.css');
$doc->addStyleSheet($this->baseurl.'/media/jui/css/bootstrap-responsive.min.css');
$doc->addStyleSheet('templates/' . $this->template . '/css/template.css');
$doc->addScript('templates/' . $this->template . '/javascript/template.js');
//sidebar configuration - determines the span classes for the sidebar and main component area
$component = $this->params->get('component-span');
if(!$this->countModules('sidebar')):
$component = 12;
endif;
$sidebar = 12 - $component;
$sidebar_pos = $this->params->get('sidebar-pos');
//navbar inverse
if($this->params->get('navbar-inverse') == 'TRUE'):
$inverse = ' navbar-inverse';
endif;
//multisite configuration - determines which template params and menu module to display depending on the base URL
$domain = $_SERVER["SERVER_NAME"];
$primary = $this->params->get('site-domain');
$sub1= $this->params->get('domain1-domain');
$sub2= $this->params->get('domain2-domain');
$sub3= $this->params->get('domain3-domain');
$sub4= $this->params->get('domain4-domain');
$sub5= $this->params->get('domain5-domain');
$menuid = $app->getMenu();
if($domain == $primary):
$logo = $this->params->get('logo');
$title = $this->params->get('site-title');
$slogan = $this->params->get('site-slogan');
$menu = '<jdoc:include type="modules" name="menu" />';
elseif($domain == $sub1):
$logo = $this->params->get('domain1-logo');
$title = $this->params->get('domain1-title');
$slogan = $this->params->get('domain1-slogan');
$menu = '<jdoc:include type="modules" name="menu-1" />';
$menuitemid = $this->params->get('domain1-menuid');
$menuitem = $menuid->getItem($menuitemid);
elseif($domain == $sub2):
$logo = $this->params->get('domain2-logo');
$title = $this->params->get('domain2-title');
$slogan = $this->params->get('domain2-slogan');
$menu = '<jdoc:include type="modules" name="menu-2" />';
$itemid = $this->params->get('domain2-menuid');
elseif($domian == $sub3):
$logo = $this->params->get('domain3-logo');
$title = $this->params->get('domain3-title');
$slogan = $this->params->get('domain3-slogan');
$menu = '<jdoc:include type="modules" name="menu-3" />';
$itemid = $this->params->get('domain3-menuid');
elseif($domain == $sub4):
$logo = $this->params->get('domain4-logo');
$title = $this->params->get('domain4-title');
$slogan = $this->params->get('domain4-slogan');
$menu = '<jdoc:include type="modules" name="menu-4" />';
$itemid = $this->params->get('domain4-menuid');
elseif($domain == $sub5):
$logo = $this->params->get('domain5-logo');
$title = $this->params->get('domain5-title');
$slogan = $this->params->get('domain5-slogan');
$menu = '<jdoc:include type="modules" name="menu-5" />';
$itemid = $this->params->get('domain5-menuid');
endif;
?>
的index.php
<?php
defined('_JEXEC') or die;
include($this->baseurl.'templates/'.$this->template.'/includes/config.php');
$default_page = new JURI($menuitem->link);
print($domain.'<br />'.$primary.'<br />'.$default_page);
if ($domain != $primary):
$link = $default_page;
$msg = 'Testing Redirect';
$app->redirect($link, $msg);
endif;
?>
<!DOCTYPE html>
<html>
<head>
<?php $this->setTitle($title.' - '.$this->getTitle()); ?>
<jdoc:include type="head" />
</head>
答案 0 :(得分:0)
这是因为$domain != $primary
失败。你获得$domain
的方式可能是原因的根源。
请看PHP $_SERVER['HTTP_HOST'] vs. $_SERVER['SERVER_NAME'], am I understanding the man pages correctly?并确保这不是问题所在。
此外,Joomla有JUri
个包可以帮助解决这个问题。如果您正在使用Joomla,最好使用它。