1

我使用的是 CakePHP 1.3,我想更改此消息:

您无权访问该位置。

到(例如):

哦对不起

消息从此代码出现:

echo $this->Session->flash('auth');

我将 app_controller 更改为

class AppController extends Controller {

var $components = array('Auth', 'Session', 'Acl');

function beforeFilter() {
    $this->Auth->authorize = 'actions';
    $this->Auth->autoRedirect = false;
    if ($this->params['controller'] == 'pages') {
        $this->Auth->allow('*');
    }
    $this->Auth->allow('pages');
    $this->Auth->loginError = "This message shows up when the wrong credentials are used";    
    $this->Auth->authError = "This error shows up with the user tries to access a part of the website that is protected.";

}

}

但我面临同样的信息。

4

3 回答 3

5

这边走:

$this->Auth->loginError = "This message shows up when the wrong credentials are used";  
$this->Auth->authError = "This error shows up with the user tries to access a part of the website that is protected.";
于 2012-10-10T11:17:44.973 回答
4

你可以自定义这个beforeFilter喜欢

function beforeFilter() {
  // ...
  $this->Auth->authError = __('You must be logged in to view this page.');
  $this->Auth->loginError = __('Invalid Username or Password entered, please try again.');
}

或者

还有另一种方法可以使 Auth 组件更加个性化。

去:

/cake/libs/controller/components/auth.php 

并找到function __setDefaults().

您可以在此处为整个应用程序自定义错误消息。

于 2012-10-11T13:47:50.573 回答
2

发生这种情况时,您可能也已将 AuthComponent 明确包含在您的 UsersController 中。确保authError在 UsersController 的 beforeFilter 方法中也设置了 ,或者确保它是 beforeFilter 调用parent::beforeFilter()以包含消息。

于 2012-10-11T14:02:57.027 回答