magento获取当前路径
piaoling 2011-05-12 17:36:25
有时候我们需要获取当前路径来做一些事情,不废话了,直接上代码
01 |
<?php |
02 |
$urlRequest = Mage::app()->getFrontController()->getRequest(); |
03 |
$urlPart = $urlRequest ->getServer( 'ORIG_PATH_INFO' ); |
04 |
if ( is_null ( $urlPart )) { |
05 |
$urlPart = $urlRequest ->getServer( 'PATH_INFO' ); |
06 |
} |
07 |
$urlPart = substr ( $urlPart , 1 ); |
08 |
$currentUrl = $this ->getUrl( $urlPart ); |
09 |
echo $currentUrl ; |
10 |
?> |
这个路径就是当前你浏览器地址栏中显示的url
如果我们想获取JS,skin目录等该如何在magento中写代码呢?
MAGENTO有一个内建的获取URL路径的功能,相关函数是getBaseUrl()在Mage类里面
01 |
//获取 magento js 路径 |
02 |
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); |
03 |
//http://你网站地址/js/ |
04 |
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); |
05 |
//http://你网站地址/index.php/ |
06 |
//获取 magento media 目录 |
07 |
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); |
08 |
//http://你网站地址/media/ |
09 |
//magento中 获取skin目录 |
10 |
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); |
11 |
//http://你网站地址/skin/ |
12 |
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); |
发表评论(评论将通过邮件发给作者):