Magento从那里重定向到页面

时间:2013-11-12 18:26:16

标签: php magento

我有一个模块,其中包含一个带有一些默认URL和一些带有表单的文本的CMS页面。在这个表格上我有字段并提交。我使用ajax验证我的字段(在我的模块的控制器中发送POST)。如果验证没问题,我会使用“succes message”重定向到同一页面。

问题是,在成功提交后我在其中进行重定向的CMS页面的默认URL可以在BO中更改 - 这就是为什么我不能只在我的控制器中$this->_redirect('default_URL'),因为这个URL可以更改。

我该怎么办?

编辑:解决方案:在成功验证后在我的控制器中使用$ this-> _redirectReferer()

3 个答案:

答案 0 :(得分:3)

尝试将“返回网址”作为隐藏字段添加到表单中,或者您可以使用$ this-> _redirectReferer()重定向回CMS页面。

请参阅http://docs.magentocommerce.com/Mage_Core/Mage_Core_Controller_Varien_Action.html#method_redirectReferer

如果您想重定向到某个特定的CMS页面(而不是放置表单的页面),您可以这样做:

  1. 添加系统配置下拉列表,以便能够选择“成功页面”(比硬编码cms页面ID好得多)

  2. 在控制器中重定向到此页面

  3. 代码:

    $pageId = Mage::getStoreConfig('mymodule/config/success_page');
    $page = Mage::getModel('cms/page')->load($pageId);
    $this->_redirect($page->getUrlKey());
    

答案 1 :(得分:0)

您可以使用getStoreConfig方法获取商店配置,例如

Mage::getStoreConfig('helloworld_options/messages/hello_message');

请参阅Alan's blog,了解如何创建自定义配置值(您可能已拥有)以及访问它们的详细说明。

答案 2 :(得分:0)

使用此代码重定向到referer

<?php Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());?>

例如,在自定义登录表单中:

<form method="post" action="<?php echo Mage::helper('customer')->getLoginPostUrl() ?>">
    <?php Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());?>
...
...