php - Cakephp 4.x CMS教程认证重定向问题
问题描述
我刚刚重新创建了 CMS 教程。当未登录并尝试编辑文章时,我被重定向到登录页面。在这里成功。登录后,我被重定向到错误页面。为什么?返回文章的重定向出错了。见下文
链接它重定向到:http://localhost/ test_cms/test_cms /articles/edit/first-post
链接它应该重定向到 http://localhost/ test_cms /articles/edit/first-post
我根据 CMS 教程处理了每个文件,但似乎无法弄清楚这里出了什么问题。
登录代码如下:
public function login()
{
$this->Authorization->skipAuthorization();
$this->request->allowMethod(['get', 'post']);
$result = $this->Authentication->getResult();
// regardless of POST or GET, redirect if user is logged in
if ($result->isValid()) {
// redirect to /articles after login success
$redirect = $this->request->getQuery('redirect', [
'controller' => 'Articles',
'action' => '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'));
}
}
解决方案
看起来您test_cms
在代码中的某处设置了额外内容,或者未经授权的操作的 URL 可能会test_cms
在您的redirect
查询参数中附加额外内容。您可以通过在条件内打印$redirect
变量来调试它。if
此外,您可能希望添加一些屏幕截图、错误消息、堆栈跟踪以及您的问题,这可以帮助人们理解问题以获得更准确的答案。