获取当前路径
$urlRequest = Mage::app()->getFrontController()->getRequest(); $urlPart = $urlRequest->getServer('ORIG_PATH_INFO'); if(is_null($urlPart)) {$urlPart = $urlRequest->getServer('PATH_INFO'); } $urlPart = substr($urlPart, 1 ); $currentUrl = $this->getUrl($urlPart); echo $currentUrl;
这个路径就是当前你浏览器地址栏中显示的url
如果我们想获取JS,skin目录等该如何在Magento中写代码呢?
Magento有一个内建的获取URL路径的功能,相关函数是getBaseUrl()在Mage类里面
//获取 magento js 路径 Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); //http://你网站地址/js/ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); //http://你网站地址/index.php/ //获取 magento media 目录 Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); //http://你网站地址/media/ //magento中 获取skin目录 Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); //http://你网站地址/skin/ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); //http://你网站地址/