CakePHP 2.4.1和PHP 5.5.9版本

CakePHP 2.4.1和PHP 5.5.9版本,php,cakephp,Php,Cakephp,我有一个CakePHP应用程序可以很好地使用PHP:5.3.8。但是,它会在PHP中生成以下错误:5.5.9 Non-static method AppHelper::isCurrent() should not be called statically, assuming $this from incompatible context 在View/Themed/Slate/Helper/AppHelper.php中,我编写了以下代码: function isCurrent($txt, $cl

我有一个CakePHP应用程序可以很好地使用PHP:5.3.8。但是,它会在PHP中生成以下错误:5.5.9

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

//查看/Helper/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'); ?>


静态函数没有定义的
$this
。也许以前的PHP版本没有警告您错误(:-?),但它可能无法工作。你必须按照PHP的要求去做(请仔细阅读错误)。@lvaroG.Vicario当我使用
$this->isCurrent()
时,它会生成一个调用视图中未定义函数的错误!isCurrent()方法是否在您的视图中?此外:
AppHelper:,AppModel:,AppController::
我知道在任何视图、模型和控制器中使用在每个视图、模型和控制器中分别定义的方法。@IsaacRajaei不,它是在AppHelper中定义的,正如我前面所说的。谢谢,它工作得很好。但是,它不需要添加public关键字。@sєmma sєmma-省略
public
关键字不会改变任何内容,因为这是默认的可见性。