0

我正在尝试使用 jquery 开发一个简单的模块,但我想禁用 mootools。我尝试在 default.php 文件中使用此代码

 $user =& JFactory::getUser();
    if ($user->get('guest') == 1) {
    $headerstuff = $this->getHeadData();
    $headerstuff['scripts'] = array();
    $this->setHeadData($headerstuff); }

    <jdoc:include type="head" />

但我收到此错误:不在对象上下文中使用 $this....

我等你的建议

4

2 回答 2

1

我不认为你在做什么是一个好主意。如果要使用 jQuery,则将其包含在 noconflict 模式中,并使用jQuery而不是$引用它。

但是,无论如何,这是您想要的代码。$this应该是一个JDocument对象,所以你需要先得到它。

 $user = JFactory::getUser();
if ($user->get('guest') == 1) {
    $doc = JFactory::getDocument();
    $headerstuff = $doc->getHeadData();
    $headerstuff['scripts'] = array();
    $doc->setHeadData($headerstuff);
}
于 2013-03-01T12:59:15.360 回答
0

我猜你想编辑 html 文档属性。你会得到错误,因为 setHeadData() 是一些 Joomla 类的方法。您不能在课堂外使用 $this 。

尝试获取文档对象并像这样调用 setHeadData:

    $doc =& JFactory::getDocument();
    $doc->setHeadData($headerstuff);

无论如何,您可以同时使用 jQuery 和 mootools。只需按照这篇文章:http ://davidwalsh.name/jquery-mootools

于 2013-03-01T12:58:32.067 回答