cakephp:登录表单未重定向

cakephp:登录表单未重定向,cakephp,redirect,authentication,Cakephp,Redirect,Authentication,当我点击登录表单上的登录按钮时,什么也没有发生。它没有重定向到/merry\u parents/report\u card。我在beforeFilter中指定了$this->Auth->loginDirect。有人知道我做错了什么吗?提前谢谢 以下是我的家长控制器、登录视图和报告卡视图 app_controller.php class AppController extends Controller { var $components=array('Auth','Session');

当我点击登录表单上的登录按钮时,什么也没有发生。它没有重定向到/merry\u parents/report\u card。我在beforeFilter中指定了$this->Auth->loginDirect。有人知道我做错了什么吗?提前谢谢

以下是我的家长控制器、登录视图和报告卡视图

app_controller.php

   class AppController extends Controller {


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

function beforeFilter(){
  if (isset($this->Auth)){
        $this->Auth->userModel='MerryParent';
        $this->Auth->loginAction=array('controller'=>'merry_parents','action'=>'login');
        $this->Auth->loginRedirect=array('controller'=>'merry_parents','action'=>'report_card');
        $this->Auth->allow('signup','login','logout');
        $this->Auth->authorize='controller';
        //$this->Auth->actionPath='controllers/';
      }
   else
        $this->Session->setFlash('Auth has not been set');  

}

function isAuthorized(){
    return true;
}
   }
    class MerryParentsController extends AppController{

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


function report_card(){
}

function register(){

}

function login(){

}

function logout(){
$this->redirect($this->Auth->logout());
}

function signup(){
        print_r($this->data);

    if (!empty($this->data)){
        //$this->Auth->password($this->data['MerryParent']['password2'] used to get what the hashed password2 would look like.        
        $this->MerryParent->set($this->data);
         //validates calls invalidFields methods which in turn populates validationErrors arrays. Validates is used to validate a record prior to updating. Needed only when you want to update certain fields in an existing record.
         if ($this->MerryParent->validates(array('fieldList'=>array('username','email','password','password2')))){

             if ($this->data['MerryParent']['password']==$this->Auth->password($this->data['MerryParent']['password2'])){

                     $this->MerryParent->id=$this->MerryParent->field('id',
                                                    array('MerryParent.username'=>$this->data['MerryParent']['username'],
                                                    'MerryParent.email'=>$this->data['MerryParent']['email'])
                                                    );
                    echo $this->MerryParent->id;

                    //die(debug($this->MerryParent->validationErrors));
                    if ($this->MerryParent->save($this->data,false))//record with $this->MerryParent->id is updated
                        {
                                                    $this->Auth->login($this->data); //automatically logs a user in after registration

                        $this->redirect('/merry_parents/report_card');
                        }
                    else
                        echo $this->Session->setFlash(__('Your admission could not be saved, please try again!',true));


                }//end if ($this->data['MerryParent']['password']....
                else
                    echo $this->Session->setFlash('Typed passwords did not match');
            }//if ($this->MerryParent->validates
    }//end if (!empty($this->data))
}
 }
 ?>
merry_parents_controller.php

   class AppController extends Controller {


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

function beforeFilter(){
  if (isset($this->Auth)){
        $this->Auth->userModel='MerryParent';
        $this->Auth->loginAction=array('controller'=>'merry_parents','action'=>'login');
        $this->Auth->loginRedirect=array('controller'=>'merry_parents','action'=>'report_card');
        $this->Auth->allow('signup','login','logout');
        $this->Auth->authorize='controller';
        //$this->Auth->actionPath='controllers/';
      }
   else
        $this->Session->setFlash('Auth has not been set');  

}

function isAuthorized(){
    return true;
}
   }
    class MerryParentsController extends AppController{

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


function report_card(){
}

function register(){

}

function login(){

}

function logout(){
$this->redirect($this->Auth->logout());
}

function signup(){
        print_r($this->data);

    if (!empty($this->data)){
        //$this->Auth->password($this->data['MerryParent']['password2'] used to get what the hashed password2 would look like.        
        $this->MerryParent->set($this->data);
         //validates calls invalidFields methods which in turn populates validationErrors arrays. Validates is used to validate a record prior to updating. Needed only when you want to update certain fields in an existing record.
         if ($this->MerryParent->validates(array('fieldList'=>array('username','email','password','password2')))){

             if ($this->data['MerryParent']['password']==$this->Auth->password($this->data['MerryParent']['password2'])){

                     $this->MerryParent->id=$this->MerryParent->field('id',
                                                    array('MerryParent.username'=>$this->data['MerryParent']['username'],
                                                    'MerryParent.email'=>$this->data['MerryParent']['email'])
                                                    );
                    echo $this->MerryParent->id;

                    //die(debug($this->MerryParent->validationErrors));
                    if ($this->MerryParent->save($this->data,false))//record with $this->MerryParent->id is updated
                        {
                                                    $this->Auth->login($this->data); //automatically logs a user in after registration

                        $this->redirect('/merry_parents/report_card');
                        }
                    else
                        echo $this->Session->setFlash(__('Your admission could not be saved, please try again!',true));


                }//end if ($this->data['MerryParent']['password']....
                else
                    echo $this->Session->setFlash('Typed passwords did not match');
            }//if ($this->MerryParent->validates
    }//end if (!empty($this->data))
}
 }
 ?>
login.ctp

  <?php
       echo $this->Form->create('MerryParent',array('action'=>'login'));
      echo $this->Form->input('username',array('label'=>'Name'));
      echo $this->Form->input('password', array('value'=>''));
      echo $this->Form->end('Login');
   ?>

报告卡.ctp

 <?php
 echo 'HALLO';

 ?>


“什么也没发生”?表格没有提交吗?那就是浏览器的问题了。我想你对什么是loginAction的理解是错误的……从我在cakephp cookbook上的阅读来看,loginAction用于将默认登录名从/users/login更改为您选择的任何其他操作。所以,这就是我在这里所做的,我将默认的/users/login改为/merry_parents/register,它显示注册链接和登录链接。这不是一个好方法(原因是现在有点长,脱离主题,但你会看到)。你没有回答“什么都没有发生”?是的,什么都没有发生,表格没有提交。单击“提交”时,它将保持在同一页面上。修改beforeFilter后,它将重定向到/merry_parents/report_card进行注册。但它仍然不适用于登录。当我单击登录按钮时,它将保持在同一页面上。它没有被重定向到$this->Auth->loginDirect中指定的/merry\u parents/report\u card。我还注意到LoginDirect不适用于注册。为此,它使用了注册函数中指定的$this->redirect。