2012-11-25 42 views
0

我使用Joomla 2.5.7,我在一个页面中遇到了$ this-> baseurl的问题。Joomla网站:baseurl不会返回正确的网址

在我的index.php文件,我unclude .js文件和.css文件与的BaseURL就像这个例子:

 <script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/jquery-1.2.6.min.js" type="text/javascript"></script> 

而且它在这种网页的正常工作:

http://mywebsite.com/index.php/myfolder

页面 “MyFolder文件” 是从类的文章列表。

当我点击这个页面中的文章是,Joomla使用这个网址:

http://mywebsite.com/index.php/myfolder/article1

在这里,一切都是不正确的(CSS,JS,...),因为我的BaseURL返回此:

/文件夹

代替:

/

而我包括的index.php不利于本页面!

您是否已遇到此问题?

如何解决?

我没有找到baseurl被定义,纠正它,你能帮助我吗?

回答

0

好的,谢谢你的回答,但我不认为你清楚地知道我只有在包含文件夹的url的问题。

我在configuration.php中找到了一个使用live_site变量的解决方案。

-1

我没有测试过这些,但也许尝试其中的一种:

JDocument::base 
JDocument::baseurl 
JURI::base() 
+0

我得到同样的问题,它返回:** http://mywebsite.com/folder/**而不是** http://mywebsite.com/** – TheFrancisOne

0

使用JURI::root()得到的Joomla

请见Joomla文档页面here的根部关于它的更多信息。此外,Joomla论坛发布了this - 同时提到Joomla 1.6的早期版本RC可能会有所帮助。

+0

我得到错误“Class'JRUI'not found “ – TheFrancisOne

+0

应该是JURI :: root()而不是JRUI!抱歉! –

+0

Oups,对不起,错误。但我得到同样的问题,它返回:** http://mywebsite.com/folder/**而不是** http://mywebsite.com/** – TheFrancisOne

0

首先你建立此功能在你的脚本的顶部

function thisSite($a){ 
$this_raw = parse_url($a); 
$b = preg_replace('#^www\.(.+\.)#i', '$1', $this_raw['host']); 
return $b; } 

然后使用功能这样

$thisSite = JURI::root(); 
// $thisSite will echo http://www.mywebsite.com/ 
$thisSite_base = thisSite($thisSite); 
// the function removes http:// and the www and the /path 
echo $thisSite_base; 

这将呼应

mywebsite .com

0

在模板中,您可以使用快捷方式$this->baseurl而不是JURI::base(true)