我需要重定向到控制器的頁面並滾動到特定的錨點。我使用在正常的Magento控制器重定向到控制器頁面的錨點
$this->_redirect("shop/boxes#".$mainSku);
以下假設$mainSku
是123,在所以我被重定向到http://example.com/shop/boxes/#123/例如末端添加一個尾隨斜線。尾部斜線失去了對錨點的滾動效果。
我怎麼能克服(以最清潔的方式)?
我需要重定向到控制器的頁面並滾動到特定的錨點。我使用在正常的Magento控制器重定向到控制器頁面的錨點
$this->_redirect("shop/boxes#".$mainSku);
以下假設$mainSku
是123,在所以我被重定向到http://example.com/shop/boxes/#123/例如末端添加一個尾隨斜線。尾部斜線失去了對錨點的滾動效果。
我怎麼能克服(以最清潔的方式)?
這個技巧!
$url = Mage::getUrl("shop/boxes#".$mainSku);
$url = substr($url, 0, -1);
$this->getResponse()->setRedirect($url);
希望這對其他人有用。
如何在getUrl
方法之外添加錨定名稱?
$url = Mage::getUrl('shop/boxes').'#'.$mainSku;
$this->getResponse()->setRedirect($url);
我遇到同樣的問題,從馬呂斯的回答是最好的解決辦法,因爲從Krt_Malta解決方案不一樣,如果你使用參數或工作有添加密鑰來激活網址。
(對不起馬呂斯,不能投票了飛機。)
我把原來的$this->_redirect()
代碼,並修改它,這樣我可以給它一個參數的錨。
現在我可以這樣使用它:
$this->_redirectAnhcor('*/*/edit', array('id' => $Id), '#products');
/**
* Set redirect into response with anchor
*
* @param string $path
* @param array $arguments
* @param string $anchor
*/
protected function _redirectAnhcor($path, $arguments = array(), $anchor = '')
{
$this->_getSession()->setIsUrlNotice($this->getFlag('', self::FLAG_IS_URLS_CHECKED));
$this->getResponse()->setRedirect($this->getUrl($path, $arguments) . $anchor);
return $this;
}
超級它幫助我 –