【问题标题】:Call a static method from CakePHP Plugin从 CakePHP 插件调用静态方法
【发布时间】:2013-08-22 02:52:27
【问题描述】:

我有一个类,其中包含一个名为“ControllerUtility”的插件类中的名为 hash 的静态方法

函数位于ControllerUtility/Model/ControllerUtility.php

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

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

我想打电话

ControllerUtility::hash( "string );

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

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

在我的控制器中

【问题讨论】:

  • I want to call ControllerUtility::hash( "string" ); - 这就是答案。

标签: php cakephp plugins static load


【解决方案1】:

你必须使用:

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

然后你可以调用:

ControllerUtility::hash("string");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多