【问题标题】:Development of a module joomla开发一个模块 joomla
【发布时间】:2026-01-11 17:50:02
【问题描述】:

我正在尝试使用 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....

等待你的建议

【问题讨论】:

    标签: php jquery joomla mootools


    【解决方案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);
    }
    

    【讨论】:

    • 我同意...禁用 Mootools 不是一个好主意。有一些默认扩展正在使用它。
    【解决方案2】:

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

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

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

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

    【讨论】: