1

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

ndm
  • 59,784
  • 9
  • 71
  • 110
ericgen
  • 43
  • 4
  • Kind of a duplicate of http://stackoverflow.com/q/1633012/1392379 as this is a purely PHP related issue – ndm Jun 18 '14 at 15:38

1 Answers1

2

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);

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

Nunser
  • 4,512
  • 8
  • 25
  • 37