如何在同一控制器文件中调用其他方法/函数?
例如:controller.php
class MyController extends JControllerLegacy
{
function test() {
$var = otherfunction();
echo $var;
}
function othermethod() {
return 'something';
}
}
我在浏览器中遇到错误。 致命错误:“调用未定义的函数othermethod()”。
我很乐意得到帮助...抱歉我的英语不好(;
答案 0 :(得分:1)
为了在同一个类中调用方法,可以使用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';
}
}
答案 1 :(得分:0)
otherfunction();
但如果编程面向对象(如您插入的代码),则必须使用 $ this-> functionName / 来调用其他函数。所以test()函数必须像这样:
function test() {
$var = **$this->otherfunction();**
echo $var;
} 有关面向对象PHP的更多信息,请参阅this
答案 2 :(得分:0)
你没有正确地调用joomla控制器。
这是语法: class component_nameControllerController_Name { }
ex:class virtuemartmartControllercort extends Jcontroller { } 这里virtmart是组件名称,cort是控制器.Controller表示这是控制器。