【发布时间】:2018-04-19 18:56:28
【问题描述】:
我正在关注 CakePHP 教程:
https://book.cakephp.org/3.0/en/tutorials-and-examples/bookmarks/part-two.html
我的 CakePHP 版本是:3.6.0
我的 PHP 版本是:7.2
这是我的 src\Controller\AppController.php
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
'unauthorizedRedirect' => $this->referer()
]);
$this->Auth->allow(['display']);
}
}
在我的 src\Controller\UsersController.php 我添加了以下方法:
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Your username or password is incorrect.');
}
}
我创建了 src\Template\Users\login.ctp 文件:
<h1>Login</h1>
<?= $this->Form->create() ?>
<?= $this->Form->control('email') ?>
<?= $this->Form->control('password') ?>
<?= $this->Form->button('Login') ?>
<?= $this->Form->end() ?>
我的浏览器提示错误:ERR_TOO_MANY_REDIRECTS
如果我尝试访问以下网址:localhost:8765/bookmarks
【问题讨论】: