cakephp:登录表单不重定向

时间:2011-09-20 04:55:48

标签: cakephp redirect authentication

当我点击登录表单上的登录按钮时,没有任何反应。它没有重定向到/ merry_parents / report_card。我在beforeFilter中指定了$ this-> Auth-> loginRedirect。有谁知道我做错了什么?提前谢谢。

以下是我的merry_parents控制器,登录视图和report_card视图

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;
}
   }

merry_parents_controller.php

    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');
   ?>

report_card.ctp

 <?php
 echo 'HALLO';

 ?>

0 个答案:

没有答案