CakePHP Auth组件的本地化 [英] CakePHP localization of Auth component

查看:57
本文介绍了CakePHP Auth组件的本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用控制器中,我有:

In my app controller I have:

public $components = array
(
    'Session',
    'Auth' => array
    (
        'loginRedirect' => array('controller' => 'devices', 'action' => 'index'),
        'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
        'authError' => 'You can\'t access that page',
        'authorize'=>array('Controller'),
        'authenticate' => array('Z1')
    )
);

如何定位错误消息?使用__()会引发错误。
谢谢

How can I localize the error message? Using __() throws an error. Thanks

推荐答案

它抛出错误,因为PHP不喜欢在数组定义中使用函数。

It throws an error because PHP doesn't like use of functions inside array definitions.

您可以做的就是在此后定义错误,在每次这样的控制器调用中

What you can do is define the error after that, in every call to the controller like this

function beforeFilter() {
    $this->Auth->authError= __('You can\'t access that page');
}

或者,另一种方法是每次都这样保留数组您输出错误(可能是在即时消息或其他内容中),将其翻译

Or, the other option is to leave your array like that, and every time you output the error (maybe in a flash message or something), translate it there

 echo __($this->Auth->authError);

但这不会让PoEdit或类似的工具识别要翻译的字符串,因此您必须手动添加。

But that won't let PoEdit or similar recognize the string to translate, so you'll have to add it by hand.

这篇关于CakePHP Auth组件的本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆