3 joomla joomla-extensions joomla2.5
我在joomla 2.5中创建了一个组件和一个插件,组件中有一个Helper文件,它有许多有用的函数,我打算调用它的一个函数,然后用这个代码调用helper中的另一个函数:
$this->getinformation();
Run Code Online (Sandbox Code Playgroud)
它给了我这个错误:
Fatal error: Call to undefined method
Run Code Online (Sandbox Code Playgroud)
我的问题是:
辅助文件通常是静态调用而不是使用$ 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
}
}
Run Code Online (Sandbox Code Playgroud)
只需在您要使用它的文档中包含这样的帮助文件:
require_once JPATH_COMPONENT.'/helpers/my_helper.php';
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它:
myHelper::myMethod($var);
Run Code Online (Sandbox Code Playgroud)
要么
myHelper::myOtherMethod($var);
Run Code Online (Sandbox Code Playgroud)