【发布时间】:2012-07-16 09:04:02
【问题描述】:
我想在我的自定义 html 块中重定向到特定的 url。
我正在尝试什么:
class Mage_Page_Block_Html_World extends Mage_Core_Block_Template {
function __construct()
{
$i = 0;
parent::__construct();
$this->setTemplate('page/html/world.phtml');
$this->setCookie();
}
public function setCookie()
{
$lang = $this->getLanguageCode();
if(isset($_GET['country'])) {
$country = $_GET['country'];
Mage::getModel('core/cookie')->set('country', $country);
} else {
$country = Mage::getModel('core/cookie')->get('country');
}
/*Redirect to cookie url*/
if($country) {
try {
$url = "http://myurl.dev/".$country."/";
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), "\n";
}
}
}
因为我在我使用的 .htaccess 中使用了多存储配置:
SetEnvIf 主机 www.myurl.dev MAGE_RUN_CODE=base
SetEnvIf 主机 www.myurl.dev MAGE_RUN_TYPE=website
SetEnvIf 主机 ^myurl.dev MAGE_RUN_CODE=base
SetEnvIf 主机 ^myurl.dev MAGE_RUN_TYPE=website
SetEnvIf 主机 www.myurl1.dev MAGE_RUN_CODE=vs
SetEnvIf 主机 www.myurl1.dev MAGE_RUN_TYPE=website
SetEnvIf 主机 ^myurl1.dev MAGE_RUN_CODE=vs
SetEnvIf 主机 ^myurl1.dev MAGE_RUN_TYPE=website
问题: 通过此重定向,我得到错误 310:重定向过多。 我不知道如何解决这个问题。
【问题讨论】:
-
尝试解释你为什么这样做,然后其他人可以建议如何做到这一点,也许可以理解你失败的原因
-
这个逻辑应该在控制器中,而不是在块中。
-
为什么这样做:我有一个登录页面,用户可以在其中选择他们的语言。语言代码存储在 cookie 中,如果用户再次输入基本 url,他将被重定向到正确的存储。 html 块通过 getChildHtml('world') 加载到我的自定义模板文件中。我在我的 phtml 文件中用一点 javascript 解决了这个问题,但是如果 s.o.知道在这个 html 块中执行此操作的解决方案,我会欣赏它。
标签: html magento redirect block