我在Joomla2.5中创建了一个组件和一个插件,组件中有一个Helper文件,它将具有许多有用的函数,我计划调用它的一个函数,然后通过以下代码调用助手中的另一个函数:
$this->getinformation();它给了我一个错误:
Fatal error: Call to undefined method我的问题是:
发布于 2012-11-21 08:28:54
辅助文件通常是静态调用的,而不使用$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-20 12:32:55
您必须包含帮助文件,并使用类名调用函数。
在插件或组件中添加以下行:
jimport( 'joomla.filesystem.folder' );
require_once JPATH_ROOT . '/components/com_xxxx/helper.php';
classname::functionname();或
如果您正在处理相同的帮助文件,请按以下方式调用
classname::functionname();https://stackoverflow.com/questions/13472274
复制相似问题