dongnanke4106 2012-07-03 10:36
浏览 63
已采纳

Yii中的onMissingTranslation事件无法正常工作

well i have a configuration like this in the components part of my config file

'components'=>array(

        'messages' => array(
            'onMissingTranslation' => array('MissingTranslation','handler'),
        ),
);

now this is my MissingTranslation class

class MissingTranslation extends CApplicationComponent{

    public function handler($event){
        $msg= $event->message;

    }

}

now I tested it by using Yii:t("hello"); where in the "hello" doesn't have any translation at all. and this creates an error

call_user_func() expects parameter 1 to be a valid callback, non-static method MissingTranslation::handler() should not be called statically

I remove the onMissingTranslation event handler and it works fine so I'm suspecting that the event handler has the problem.

Is this a bug already of Yii? or I did something bad again?

UPDATE

this is the answer from Yii

https://github.com/yiisoft/yii/issues/902#issuecomment-6732258

I hope this will help to someone will encounter the same issue

  • 写回答

1条回答 默认 最新

  • doubi6669 2012-07-03 15:42
    关注

    As you are extending a class and to use a class without creating an Instance or Object you need to mark it as static so that its properties and methods become visible.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化