【问题标题】:How Magento controller redirects work?Magento 控制器重定向如何工作?
【发布时间】:2011-12-05 07:04:02
【问题描述】:

我已经制作了重定向到 url 的 Magento 控制器,但由于某种原因 url 是错误的。

我的控制器:

public function indexPostAction()
{
    // Do stuff here
    $this->_redirect('module/controllername');      
}

此控制器重定向到 url 模块/控制器名称/indexPost,但我已将其重定向到模块/控制器名称,这是我的模块的索引页面。为什么它没有重定向到正确的地址?

【问题讨论】:

    标签: php magento magento-1.4


    【解决方案1】:

    该重定向会将您重定向到由controllername 控制器的indexAction 函数控制的www.yourstore.com/module/controllername。 indexAction 函数有什么作用?如果你只是想让它显示布局的内容,那么你可以这样做

    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
    

    【讨论】:

    • 感谢帮助,我的代码实际上有错误,因此从未到达该重定向代码,但它没有向 magento 日志抛出任何错误,所以在调试代码之前我没有发现.
    【解决方案2】:
    Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
    

    【讨论】:

    • 感谢您提供此代码 sn-p,它可能会提供一些有限的即时帮助。 proper explanation 将通过展示为什么这是解决问题的好方法,并使其对有其他类似问题的未来读者更有用,从而大大提高其长期价值。请edit您的回答添加一些解释,包括您所做的假设。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-28
    相关资源
    最近更新 更多