我无法在cakePHP 2.4中登录用户,请参阅我创建此文档的文档。它说已成功登录,并且也重定向到目标URL(用户/登录操作),但$this->Auth->username
和$this->Auth->password
保持空白,没有会话被创建。尝试使用错误的凭据登录时,它也会被重定向。并且还告诉我登录成功了。我现在无能为力。在cakePHP中进行身份验证2.4
AppController.php
class AppController extends Controller {
public $components = array(
'Session',
'DebugKit.Toolbar',
'Auth' => array(
'loginAction' => array('controller' => 'users', 'action' => 'login', 'plugin' => false),
'loginRedirect' => array('controller' => 'users', 'action' => 'loggedin'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'loggedout'),
'authError' => 'UNABLE TO LOG IN.'
)
);
public function beforeFilter(){
$this->Auth->userModel = 'User';
$this->Auth->fields = array('username' => 'username', 'password' => 'password');
$this->Auth->allow('index','display','login','show_reg_form', 'view','signup');
}
}
UsersController.php
我只粘贴登录功能:
public function login() {
if ($this->request->is('post')) {
if($this->Auth->login(/*$this->request->data*/)){
$this->Session->setFlash(__('Successfully logged in.'));
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
login.ctp
相关部分是:
<div class="container-login users form">
<?php echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end(__('Login',true));?>
</div>
'__('Login',true)'应该是__('Login')'。这不再是蛋糕1.3了。 – mark
您是否将参数传递给$ this-> Auth-> login?或者你在这里评论他们? –
我没有通过他们,因为当我上次取消评论时,我可以登录任何内容。我读过文档,它应该没有指定的参数。 –