我添加了一个重定向到checkout/onepage。在继续从购物车结账之前,将客户重定向到登录/注册页面。我没有修改Accountcontroller.php或login. php .
重定向工作正常,但登录页面上的错误信息丢失(例如错误的密码,未知的电子邮件地址不显示)。其他页面上的消息正常,登录页面上的消息只有在删除cookie后才能重新开始工作。
我在onpage .html开头使用的重定向代码:
if (!$this->helper('customer')->isLoggedIn()) {
header("Location: /customer/account/login/");
exit();
}
登录。phtml <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
被正确调用
我还尝试用
扩展重定向代码Mage::getSingleton('core/session')->addError("Error message");
session_write_close();
直接在重定向之后显示消息,而不是在输入错误的密码/电子邮件时显示消息。是否有一种方法可以使消息工作而无需创建自定义控制器/模块?
你不需要使用PHP的header
函数,使用Magento内置的重定向方法。
Mage::getSingleton('core/session')->addError('Error to display here.');
$this->_redirect('customer/account/login');