1. 程式人生 > >Magento 獲取當前的URL/Magento中獲取URL相關引數的方法

Magento 獲取當前的URL/Magento中獲取URL相關引數的方法

$currentUrl = $this->helper('core/url')->getCurrentUrl(); //在社會化分享中,當前頁面的URL地址非常有用 <a addthis:url="<?php echo $this->helper('core/url')->getCurrentUrl(); ?>">Share on Facebook</a><span>


Magento中獲取URL相關引數的方法全部封裝在了getRequest()中。獲取URL引數的方式比直接使用PHP方法要簡單更多。如下URL,是Magento高階搜尋中很常見的URL地址。

http://127.0.0.1/project_auto/index.php/catalogsearch/advanced/result/?car_make_select[]=24&car_model_select[]=30&car_fit_year_select[]=17


//獲取所有引數到關聯陣列中 $arr = $this->getRequest()->getParams(); //直接獲取car_make_select $car_make_select = $this->getRequest()->getParam('car_make_select'); //如果當前層未定義getRequest()方法,可以通過如下方式呼叫
$request = Mage::app()->getRequest()->getParams();