在 Magento 中获取皮肤路径? [英] Get skin path in Magento?
问题描述
我的 Magento 商店有一些自定义 PHP 函数,我存储在 myfunc.php 中,我需要从几个不同的 .phtml 文件中获取它.我该怎么做?
I have a few custom PHP functions for my Magento store that I stored in myfunc.php and I need to require it from in a few different .phtml files. How do I do that?
我的意思是我可以使用绝对路径,但在迁移到另一台服务器时会很脏并且可能会出现问题.
I mean I can use an absolute path but that would be dirty and probably problematic when migrating to another server.
现在我坚持:
require('/home/myuser/public_html/app/design/frontend/default/mytheme/myfunc.php');
如何以编程方式引用皮肤路径 (/home/myuser/public_html/app/design/frontend/default/mytheme/)?
How do I refer to the skin path ( /home/myuser/public_html/app/design/frontend/default/mytheme/ ) programmatically?
推荐答案
Magento 主题处理实际 url 的方式是这样的(在视图部分 - phtml 文件中):
The way that Magento themes handle actual url's is as such (in view partials - phtml files):
echo $this->getSkinUrl('images/logo.png');
如果您需要磁盘上图像目录的实际基本路径,请使用:
If you need the actual base path on disk to the image directory use:
echo Mage::getBaseDir('skin');
这篇很棒的博文中提供了更多基本目录类型:
Some more base directory types are available in this great blog post:
http://alanstorm.com/magento_base_directories
这篇关于在 Magento 中获取皮肤路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!