我在生产服务器上的Auth组件存在问题。当我输入用户名和密码并单击登录时,除密码文本框自行清除外,没有任何反应。我得到'我登录失败'。我完全不知道为什么它不会进入'if($ this-> Auth-> user())'。
早先在我的开发服务器上,这个Auth组件工作得很好。我能够登录用户,一旦用户登录,他/她的孩子的报告卡pdf文件将被显示。
任何人都可以指出我犯了什么错误吗?谢谢。
merry_parents_controller.php
class MerryParentsController extends AppController{
var $name='MerryParents';
function beforeFilter(){
parent::beforeFilter();
$this->Auth->autoRedirect=false;
//$this->redirect($this->Auth->redirect());
}
function login(){
echo "i'm in login";
if ($this->Auth->user()){
debug($this->Auth->user());
$this->data=$this->Auth->user();
if (!empty($this->data)){
$student_info=$this->MerryParent->Student->getStudents($this->data['MerryParent']['id']);
$this->set('student_info',$student_info);
print_r($student_info);
$this->redirect(array('controller'=>'aptitudes','action'=>'viewpdf',$student_info['Student']['id']));
//$this->render('/aptitudes/viewpdf');
}
else{
echo 'Auth user has not been set';
}
}
else
echo "Failure";
}
}
login.ctp
<?php
//var_dump($this->data);
$this->Session->flash('auth');
echo $this->Form->create('MerryParent',array('action'=>'login'));
echo $this->Form->input('MerryParent.username',array('label'=>'Name'));
echo $this->Form->input('MerryParent.password', array('value'=>''));
echo $this->Form->end('Login');
?>
app_controller.php
class AppController extends Controller {
var $components=array('Auth','Session','Cookie','Email','Security','RequestHandler','Cookie');
var $helpers = array('Html','Form','Ajax','Javascript','Session');
function beforeFilter(){
if (isset($this->Auth)){
$this->Auth->userModel='MerryParent';
$this->Auth->loginAction=array('controller'=>'merry_parents','action'=>'login');
/*var_dump($this->data);
debug($this->Auth->user);*/
$this->Auth->allow('*');
$this->Auth->loginRedirect=array('controller'=>'aptitudes','action'=>'viewpdf');
$this->Auth->logoutRedirect=array('controller'=>'merry_parents','action'=>'register');
$this->Auth->authorize='controller';
}
else
$this->Session->setFlash('Auth has not been set');
}
function isAuthorized(){
return true;
}
事情是真的错了你'login'功能。您正在通过执行$ this-> data = $ this-> Auth-> user()来清除传递给此函数的数据。这只会在你已经登录时才起作用。你应该首先通过将这个 - >数据传递给Auth登录函数来登录... – 2012-01-30 18:08:29