从行为CakePHP 2.10.12调用特定函数不起作用

从行为CakePHP 2.10.12调用特定函数不起作用,cakephp,behavior,cakephp-2.x,Cakephp,Behavior,Cakephp 2.x,干草。目前,我正在CakePHP 2.10.12的Behavior中创建一个函数,如下所示: <?php App::uses('CakeTime', 'Utility'); App::uses('CakeNumber', 'Utility'); class ConverterBehavior extends ModelBehavior { private $timezone; private $locale; private $currency; func

干草。目前,我正在CakePHP 2.10.12的Behavior中创建一个函数,如下所示:

<?php
App::uses('CakeTime', 'Utility');
App::uses('CakeNumber', 'Utility');
class ConverterBehavior extends ModelBehavior {
    private $timezone;
    private $locale;
    private $currency;

    function hellow() {
        return "Hellow from behavior";
    }

    function initConverter($locale, $timezone, $currency) {
        $this->locale = $locale;
        $this->timezone = $timezone;
        $this->currency = $currency;
        setlocale(LC_ALL, $locale);
    }

    public function getCurrentLocale() {
        return $this->locale;
    }

    function convertCurrency($currencyAmount) {
        return CakeNumber::currency($currencyAmount, $this->currency);
    }

    function convertDate($date) {
        return CakeTime::i18nFormat($date, null, false, $this->timezone);
    }

}
?>
<?php

class Test extends AppModel {
    public $actsAs = array('Converter');
}
public function converterModel() {
    $this->Test->initConverter('ja_JP', 'Asia/Tokyo', 'JPY');
    $temp = $this->Test->convertCurrency(23456789901.123456);
    debug($this->Test->hellow());
    // $this->set('jpDate', $this->Test->convertDate(new DateTime));
}
问题是initConverter无法初始化。我检查从控制器输入的变量,所有这些变量都是空的,这很奇怪。但是当我在behavior中调用hellow函数时,结果显示在我的视图中。那么这里少了什么吗? 多谢各位

注: 这是“我的视图”中显示的错误消息:

查看警告/通知,您正在接收一个对象,其中您需要一个字符串/数字

外部调用的行为方法的第一个参数始终是该行为所附加到的模型的实例,即方法签名应如下所示:

function initConverter(Model $model, $locale, $timezone, $currency)

function convertCurrency(Model $model, $currencyAmount)

// etc...
另见