从CakePHP Plugin调用一个静态方法


Call a static method from CakePHP Plugin

我有一个类,它的静态方法叫做hash,来自一个名为"ControllerUtility"的插件类

该函数位于ControllerUtility/Model/ControllerUtility.php

public static function hash( $string )
{
    return hash( 'sha256' , $string );
}

我如何在模型或控制器中以静态方式调用这个方法,我不想将这个类加载到$this中,因为这会给我一个对象的实例。

我想打电话给

ControllerUtility::hash( "string );

而不是将函数更改为非静态函数,然后调用

$this->ControllerUtility->hash( "string );`

您必须使用:

App::uses('ControllerUtility', 'ControllerUtility.Model');

然后可以调用:

ControllerUtility::hash("string");