Prestashop 1.6 header 在模块中的位置

Prestashop 1.6 header location in module

嗨,我写了我的第一个模块,我想添加重定向到登录页面:index.php?controller=authentication

我添加函数:header("Location: index.php?controller=authentication");

也尝试过这样做: Tools::redirect('authentication.php');

每次都是这样的错误:

This web page has a redirect loop ERR_TOO_MANY_REDIRECTS

有什么建议吗?

显示此网络浏览器错误是因为此重定向重复执行多次。我认为,您的模块代码也在授权页面上执行,因此您尝试从授权页面重定向到授权页面。代码一次又一次地执行...

感谢问题已解决!

@deniskoronets 你说得对:)

在其他论坛上有人给我这个代码:

if((strpos($url,'login')!==false) || (strpos($url,'authentication')!==false)) $page='loginpage'; else $page='otherpage'; if (!$this->context->customer->isLogged() && $page != 'loginpage'){ Tools::redirect('authentication'); }

很有帮助。