【发布时间】:2014-01-11 19:01:59
【问题描述】:
我正在使用 Cake 的 Auth 组件,但在使用 scope 时似乎无法弄清楚如何设置特定的闪存数据/错误消息。
通过将active 从0 更改为1 进行测试时,我可以确认scope 参数有效,但是如果scope 返回false,我将获得与我的login 方法相关联的闪存数据,@ 987654328@.
用户控制器
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.'));
}
}
应用控制器
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 方法绑定特定的错误消息?
【问题讨论】:
标签: php cakephp authentication