2012-10-10 39 views
1

更改登錄消息我使用CakePHP 1.3,我想改變這個消息:如何在CakePHP中

您無權訪問該位置。

至(例如):

哦抱歉

從該代碼將顯示消息:

回聲$這 - >會話級>閃光(」 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."; 

} 

}

但尚未我面對相同的消息。

+0

我將你的代碼添加爲弓,但我面臨同樣的消息 – aya

回答

2

發生這種情況時,您可能也已明確將AuthComponent包含在您的UsersController中。請確保在UsersController的beforeFilter方法中也設置authError,或者確保beforeFilter調用parent::beforeFilter()來包含該消息。

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."; 
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.'); 
} 

OR

還有另一種方式,使驗證組件更加個性化。

轉到:

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

並找到function __setDefaults()

您可以在這裏爲整個應用程序定製錯誤消息。