1
我在登錄頁面上的登錄鏈接沒有帶我登錄頁面。相反,它將我帶到了login_redirect頁面的report_card頁面。我在設置cookie的登錄功能,然後我設置$ this - >重定向($ this-> Auth->重定向());我在設置autoRedirect false false因爲我設置cookie在登錄功能,cakephp:登錄鏈接不會把我帶到登錄頁面,而是它帶我登錄我的登錄頁面
有人可以幫我嗎?提前致謝。
我的代碼:
register.ctp
<?php
echo $this->Html->link('Sign Up','/merry_parents/signup',array()).' for new user |'.$this->Html->link('Login','/merry_parents/login',array()).' for existing user';
?>
app_controller.php
class AppController extends Controller {
var $components=array('Auth','Session','Cookie');
function beforeFilter(){
if (isset($this->Auth)){
$this->Auth->userModel='MerryParent';
$this->Auth->loginAction=array('controller'=>'merry_parents','action'=>'login');
//var_dump($this->data);
$this->Auth->loginRedirect=array('controller'=>'merry_parents','action'=>'report_card');
$this->Auth->allow('signup','login','logout','display');
$this->Auth->authorize='controller';
}
else
$this->Session->setFlash('Auth has not been set');
}
function isAuthorized(){
return true;
}
merry_parents_controller.php
<?php
class MerryParentsController extends AppController{
var $name='MerryParents';
var $helpers=array('Html','Form');
function beforeFilter(){
$this->Auth->autoRedirect=false;
parent::beforeFilter();
}
function report_card(){
}
function register(){
}
function login(){
if ($this->Auth->user()){
if (!empty($this->data)){
$this->MerryParent->id=$this->MerryParent->field('id',array(
'MerryParent.username'=>$this->data['MerryParent']['username'],
'MerryParent.password'=>$this->data['MerryParent']['password']
)
);
echo 'id: '.$this->MerryParent->id;
$this->Cookie->write('MerryParent.id',$this->MerryParent->id,false,0);
$this->set('id',$this->Cookie->read('MerryParent.id'));
}
$this->redirect($this->Auth->redirect());
}
}
report_card.ctp
<?php
var_dump($this->data);
echo 'HALLO';
if (isset($id))
echo $id;
else
echo 'id has not been set';
?>