我有一个CakePHP应用程序与PHP: 5.3.8工作良好。但是,它会在PHP中生成以下错误:
Non-static method AppHelper::isCurrent() should not be called statically, assuming $this from incompatible context
在View/Themed/Slate/Helper/AppHelper.php
我做了这个代码:
function isCurrent($txt, $className = 'active'){
if ($txt == strtolower($this->name.$this->action)){
return $className;
}
else{
return '';
}
}
过去,在升级PHP之前,我习惯从视图中调用这个函数,如下所示:
<?php echo AppHelper::isCurrent('contactsindex', 'active'); ?>
我试图用public static
前缀函数名来消除此错误,但未能解决此问题。我需要知道如何解决这个问题?
tr this
//视图/帮助/AppHelper
class AppHelper extends Helper {
public function isCurrent($txt, $className = 'active'){
if ($txt == strtolower($this->name.$this->action)){
return $className;
}
else{
return '';
}
}
}
//视图<?php echo $this->Html->isCurrent('contactsindex', 'active'); ?>