我正在创建一个PHP脚本,在那里我试图反向工程一个Joomla插件的社区生成器。为此,我需要在一个PHP类中构建几个自定义函数。下面是帮助定义问题的代码片段:
function gethelloworldTab() {
$this->cbTabHandler();
}
function showMeThaMoney(){
echo 'cashola';
}
function getDisplayTab($tab,$user,$ui) {
global $_CB_framework;
$baba = $this->showMeThaMoney();
$return = null;
$params = $this->params; // get parameters (plugin and related tab)
$is_helloworld_plug_enabled = $params->get('hwPlugEnabled', "1");
$helloworld_tab_message = $params->get('hwTabMessage', "");
if ($is_helloworld_plug_enabled != "0") {
if($tab->description != null) {
$return .= "\t\t<div class=\"helloworld_class\">"
. $tab->description // html content is allowed in descriptions
. "</div>\n";
}
$return .= '\t\t<div>\n'
. "<p>\n"
. htmlspecialchars($helloworld_tab_message) . "\n" // make all other output html-safe
. "</p>\n"
. $baba . "\n"
. "</p>\n"
. "</div>\n";
}
return $return;
}
}如您所见,我希望在getDisplayTab函数之外构建我的自定义类。然后,我将使用所有自定义函数变量在$result输出中构建视图。
有更好的办法吗?我犯了一个简单的错误吗?
更新:我已经将$baba = showMeThaMoney();更改为$baba = $this->showMeThaMoney();,但是cashola被回放到页面顶部。相反,我希望将cashola回显应用于变量并通过return $return;语句显示。
发布于 2014-03-05 00:13:52
要引用类的函数(即类的方法),不能直接调用该函数。你得在课上打个电话。这通常是用$this完成的。
所以你想做这样的事:
$baba = $this->showMeThaMoney();这实际上应该调用showMeThaMoney函数作为插件类的一部分。
https://stackoverflow.com/questions/22185010
复制相似问题