重定向到所选商店的最佳方式

时间:2011-05-19 13:50:34

标签: php magento redirect

我设置了一个有几个商店的magento网站,我在一个页面中列出了所有商店,用户可以使用这样的表格拿起最近的商店

    <form action="<?php echo  ;?>"  method="post">
        <input type="submit" value="select store" />
    </form>

    <form action="<?php echo  ;?>"  method="post">
        <input type="submit" value="select store" />
    </form>

在动作属性中,我想根据他的ID设置每个商店的网址... 可能吗? 有没有更好的方法(可能避免使用GET参数)?

编辑: 最后,我用这个片段实现了我想要的东西

echo '<p><a href="' . Mage::getUrl() . '?___store=' . $store . '">pick up this restaurant</a></p>';

这与clockworkgeek的建议非常接近

echo '<p><a href="' .Mage::getUrl('', array('___store'=>$store)) . '">pick up this restaurant</a></p>';

但结果不同:

我的测试:

http://test.mysite.com/?___store=3

clockworkgeek代码:

http://test.mysite.com/___store/3/

第一个链接工作正常,第二个链接导致404 ...

另外,我尝试这个没有产生任何代码的代码,不知道为什么?

Mage::app()->setCurrentStore(5);
$this->_redirect('');

重定向工作正常,但我仍然在同一个商店,这是使用setCurrentStore函数的好方法吗?

然后我终于有了这个,但我可以在网上找到合适的例子...... 我怎么能用它,以及相关的问题我怎么能得到所有magento控制器的列表?

 $this->_forward('defaultNoRoute');

THX

2 个答案:

答案 0 :(得分:1)

也许你在考虑getUrl()。例如:

echo Mage::getUrl('', array('_store'=>$storeId));

http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/geturl_function_parameters

答案 1 :(得分:0)

您应该使用JQuery事件绑定提交按钮,然后使用window.location重定向到选定的商店。

它应该与第一个答案中给出的代码非常相似: Redirect automatically when selecting an item from a select drop-down list