从CakePHP插件调用静态方法

时间:2013-06-16 21:47:05

标签: php cakephp plugins static load

我有一个带有静态方法的类,该方法名为hash,来自名为“ControllerUtility”的插件类

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

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

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

我想打电话

ControllerUtility::hash( "string );

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

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

在我的控制器中

1 个答案:

答案 0 :(得分:2)

您必须使用以下内容包含它:

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

然后你可以打电话:

ControllerUtility::hash("string");