Cakephp身份验证重定向问题

时间:2011-07-12 13:01:40

标签: php cakephp authentication

我无法获取Auth组件重定向。

我有一个登录表单,我希望将用户保留在他登录的页面上。例如,如果他正在查看联系我们页面,我想在登录后将他留在那里。我已将登录页面作为我的登录页面进行验证。否则我无法验证密码空白字段。这是我的用户的控制器代码:

函数beforeFilter(){

    $this->Auth->allow('register');
         $this->Auth->autoRedirect = false;
    parent::beforeFilter();

}

function loginaction(){

     if($this->data){
    if($this->data['User']['email']=='')
           $this->Session->setflash('E-Mail cannot be blank');
    elseif ($this->data['User']['password']=='')
        $this->Session->setflash('Password cannot be blank');
    else {
                 $this->data['User']['password']=$this->Auth->password($this->data['User']['ppassword']);
         if($this->User->validateUser($this->data)){
         $this->Auth->login($this->data);
         $this->redirect($this->Auth->redirect()); 

} }

以下是我的app_controller代码:

函数beforeFilter(){

        $this->Auth->fields = array(
        'username' => 'email',
        'password' => 'password'
        );

        $this->Auth->loginAction=array('controller'=>'users', 'action'=>'loginaction');


     }

这将重定向到用户注销的页面。但我希望重定向应该发生在用户单击登录按钮的页面上。我没有得到我错的地方。

1 个答案:

答案 0 :(得分:2)

如果您需要重定向到referer页面,您可以使用:

$this->redirect($this->referer());
相关问题