【问题标题】:can't use __() in AppController cakephp不能在 AppController cakephp 中使用 __()
【发布时间】:2014-09-11 17:24:21
【问题描述】:

当我使用 __() 函数在 AppController 中翻译消息时,我收到以下错误:

PHP 解析错误:语法错误,意外 '(',期待 ')'

这是我的代码:

public $components = array(
    'Session',
    'Acl',
    'Auth' => array(
         'authError' => __('Did you really think you are allowed to see that?'),        
         'authorize' => array(
            'Actions' => array('actionPath' => 'controllers')
        )
    )
);

__() 应该是一个全局函数,对吧?因为似乎 PHP 没有调用它。

【问题讨论】:

标签: php cakephp


【解决方案1】:

这不是 php 的问题,而是一个非常基本的 php 错误。解析器已经告诉你了。

您不能在属性声明中使用函数。

http://php.net/manual/en/language.oop5.php

【讨论】:

    【解决方案2】:

    您不能在属性声明中调用函数,因此会出现错误。 Call a function while setting class properties

    您必须在应用程序的另一个位置翻译 authError。也许 beforeRender 或 beforeFilter 会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-08
      • 1970-01-01
      • 2014-09-10
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多