我正在遵循烹饪书https://book.cakephp.org/authentication/1.1/en/index.html 中的指南。但是我的代码不断抛出错误
在我的 app/Application.php 中,我像这样在函数引导程序中调用了身份验证插件
public function bootstrap()
{
parent::bootstrap();
$this->addPlugin('DebugKit');
$this->addPlugin('Authentication');
在我的AppController.php 中,我已经这样设置了
/** INITIALIZE **/
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler', [
'enableBeforeRedirect' => false,
]);
/**
*$this->loadComponent('Flash');
*
* load authenticator
* [$this->loadComponent description]
* @var [type]
*
*/
$this->loadComponent('Authentication.Authentication', [
'logoutRedirect' => false // Default is false
]);
/** INITIALIZE **/
}
和我的UsersController.php处理来自 https:localhost/users/login 的请求
public function login()
{
//$this->render(false);
$this->viewBuilder()->layout('Common/login');
$session = $this->request->session();
/*
**AUTHENTICATION
*/
$result = $this->Authentication->getResult();
debug($result);
// regardless of POST or GET, redirect if user is logged in
if ($result->isValid()) {
$user = $request->getAttribute('identity');
// Persist the user into configured authenticators.
$this->Authentication->setIdentity($user);
$session->write('user_data',$user);
$redirect = $this->request->getQuery('redirect', ['controller' => 'Users', 'action' => 'display', 'index']);
return $this->redirect($redirect);
}
// display error if user submitted and authentication failed
if ($this->request->is(['post']) && !$result->isValid()) {
$this->Flash->error('Invalid username or password');
}
/*
**AUTHENTICATION
*/
}
我已经研究了几个小时,需要这个家伙的帮助:)
慕斯王