重定向到选定商店的最佳方式
我设置了一个包含多个商店的 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>
在操作属性中,我想设置每个商店的 url根据他的身份证... 是否可以? 有没有更好的方法来继续(也许避免 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');
谢谢
I set a magento website with several stores, I'm making a list of all thoses stores in a page where the user can pick up the nearest one using a form like this
<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>
In the action attribute I would like to set the url of each store according to his Id...
Is it possible?
Is there a better way to proceed (maybe avoiding GET parameter)?
Edit:
Finally I achieve what I was looking for with this snippet
echo '<p><a href="' . Mage::getUrl() . '?___store=' . $store . '">pick up this restaurant</a></p>';
It's quite close of what clockworkgeek suggest
echo '<p><a href="' .Mage::getUrl('', array('___store'=>$store)) . '">pick up this restaurant</a></p>';
but results are differents:
my test:
http://test.mysite.com/?___store=3
clockworkgeek code:
http://test.mysite.com/___store/3/
The first link is working fine, the second lead to a 404 one...
Also I try this code which is producing nothing, Any idea why ?
Mage::app()->setCurrentStore(5);
$this->_redirect('');
The redirection is working fine, but I'm still on the same store, Is it the good way of using setCurrentStore function?
then I finally have a go with this one, but I can find suitable example on the net about it...
how can I using it, and related question how can i Hve the list of all the magento controllers ?
$this->_forward('defaultNoRoute');
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您正在考虑
getUrl()
。例如:http://www.magentocommerce.com/wiki/5__-_modules_and_development/参考/geturl_function_parameters
Perhaps you are thinking of
getUrl()
. For example:http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/geturl_function_parameters
您应该使用 JQuery 事件绑定提交按钮,然后使用
window.location
重定向到所选商店。它应该与第一个答案中给出的代码非常相似:
从列表中选择项目时自动重定向选择下拉列表
You should bind the submit button using JQuery events and then use
window.location
to redirect to the selected store.It should be quite similar to the code given in the first answer here:
Redirect automatically when selecting an item from a select drop-down list