2014-01-11 78 views
1

我正在使用Cake的Auth组件,并且似乎无法弄清楚如何在使用scope时设置特定的闪存数据/错误消息。Cakephp验证范围错误消息

测试时由0改变active1,我可以确认scope参数的作品,但是如果scope返回false,我得到我的login方法,Your username or password was incorrect.相关的闪存数据。

UsersController

public function login(){ 
    if($this->request->is('post')){ 
     if($this->Auth->login()){ 
      $this->Session->setFlash('You are logged in!'); 
      return $this->redirect($this->Auth->redirect()); 
     } 

     $this->Session->setFlash(__('Your username or password was incorrect.')); 
    } 
} 

AppController的

public $components = array(
    'DebugKit.Toolbar', 
    'Acl', 
    'Auth' => array(
     'authorize' => array(
      'Actions' => array('actionPath' => 'controllers') 
     ), 
     'authenticate' => array(
      'Form' => array(
       'fields' => array('username' => 'email'), 
       'scope' => array('active' => '1') 
      ) 
     ) 
    ), 
    'Session' 
); 

public function beforeFilter() { 
    $this->Auth->loginAction = array(
     'controller' => 'Users', 
     'action' => 'login' 
    ); 
    $this->Auth->logoutRedirect = array(
     'controller' => 'Users', 
     'action' => 'login' 
    ); 
    $this->Auth->loginRedirect = array(
     'controller' => 'Users', 
     'action' => 'index' 
    ); 
} 

是否有可能结合特定错误消息为每个scope参数和login方法?

回答

1

CakePHP中:)很简单 可以在控制器 简单的每个方法自定义错误消息,你这样做,因为我说的^ _^

Exmple: 
<?php 
    public function accessSite(){ 
    //disable default message authError of Auth 
    $this->Auth->authError = false; 
    $message = 'You not have permission access here'; 
    //set new custom message 
    $this->Auth->flash($message); 
    }