我有一个自定义表单,其中包含一个调用我的模块控制器的操作,我想阻止重定向并停留在提交表单的页面上,但是当我尝试在控制器索引操作中添加通配符时,我收到“太多”重定向错误'

$this->_redirect('*/*/');

我也尝试过

$this->_redirectReferer();

$this->_redirectReferer('*/*/');

这是我的模块控制器中的索引操作

public function indexAction()
{
    $params = Mage::app()->getRequest()->getPost();

    if (isset($params['country'])) {
        $this->setCountry((string)$params['country'], isset($params['hide']));
    }

    if (isset($params['currency'])) {
        $this->setCurrency((string)$params['currency']);
    }
    $this->_redirectReferer();
}

下面是我的表单,它发布到我的控制器

<form method="post" action="<?php echo Mage::getUrl('locale/switch'); ?>">
    ....
</form>

有没有更好的方法来提交此表单而不重定向到控制器。

有帮助吗?

解决方案

答案并不涉及强制 Magento 留在页面上,因为

$this->_redirectReferer()

为我们很好地处理了这种行为。问题本身是由于某些页面具有安全 URL,这意味着 Magento 在提交表单时会重定向 https 解决方案是改变:

<?php echo Mage::getUrl('locale/switch'); ?>

<?php echo Mage::getUrl('locale/switch',array('_secure'=>true)); ?>

现在可以通过安全和不安全的 URL 提交表单,而无需重定向

许可以下: CC-BY-SA归因
scroll top