Php Joomla调用内部控制器函数
如何在同一控制器文件中调用其他方法/函数 例如:controller.phpPhp Joomla调用内部控制器函数,php,joomla,controller,components,Php,Joomla,Controller,Components,如何在同一控制器文件中调用其他方法/函数 例如:controller.php class MyController extends JControllerLegacy { function test() { $var = otherfunction(); echo $var; } function othermethod() { return 'something'; } } 我在浏览器中遇到一个错误。 致命错误:“调用未定义的
class MyController extends JControllerLegacy
{
function test() {
$var = otherfunction();
echo $var;
}
function othermethod() {
return 'something';
}
}
我在浏览器中遇到一个错误。
致命错误:“调用未定义的函数othermethod()”
我很高兴能得到帮助。。。抱歉,我的英语不好(;为了在同一类中调用方法,您可以使用
this
。要调用函数,您需要包含具有函数定义的文件
class MyController extends JControllerLegacy
{
function test() {
//include_once file_has_otherfunction_definition.php
//$var = otherfunction();
$var = $this->othermethod();
echo $var;
}
function othermethod() {
return 'something';
}
}
在平面php编程中,您可以仅通过函数名调用函数,如:
otherfunction();
但如果编程面向对象(如插入的代码),则必须使用$this->functionName/调用其他函数。因此test()函数必须如下所示:
function test() {
$var = **$this->otherfunction();**
echo $var;
}
有关面向对象PHP的更多信息,请参见您没有正确调用joomla controller 以下是语法: 类组件\u名称控制器\u名称{ } ex:class VirtueMartController扩展了Jcontroller{ }
这里virtuemart是组件名,cort是控制器。控制器表示这是控制器。非常感谢Irfan:)非常感谢mohsenkw。。。好的网站,合格的用户,快速的响应!我喜欢:)