3

我在 joomla 2.5 中创建了一个组件和一个插件,组件中有一个Helper文件,它将有许多有用的功能,我计划调用它的一个函数,然后通过这段代码调用助手中的另一个函数:

$this->getinformation();

它给了我这个错误:

Fatal error: Call to undefined method

我的问题是:

  • 为什么我不能在 Joomla 的助手中调用函数?
  • 如何在辅助类中调用函数?
  • 我在这段代码中遗漏了任何类结构吗?
4

2 回答 2

5

帮助文件通常是静态调用的,而不是使用 $this

首先创建您的帮助文件并添加如下方法:

Class myHelper {

    //This method can call other methods
    public static function myMethod($var) {

        //Call other method inside this class like this:
        self::myOtherMethod($var);

    }

    //This method is called by myMethod()
    public static function myOtherMethod($var) {

        //Put some code here

    }

}

只需在您要使用的文档中包含这样的帮助文件:

require_once JPATH_COMPONENT.'/helpers/my_helper.php';

然后像这样使用它:

myHelper::myMethod($var);

或者

myHelper::myOtherMethod($var);
于 2012-11-21T08:28:54.663 回答
0

您必须包含帮助文件并使用类名调用该函数

在插件或组件中添加以下行:

jimport( 'joomla.filesystem.folder' );
require_once JPATH_ROOT . '/components/com_xxxx/helper.php';

classname::functionname();

或者

如果您正在处理相同的帮助文件意味着然后像这样调用

classname::functionname();
于 2012-11-20T12:32:55.987 回答