如何获取用于 url 的后缀(在代码中)?

发布于 2024-10-26 11:53:23 字数 69 浏览 1 评论 0原文

Magento 可以添加用户定义的后缀以附加到 url 上。我想从我的代码中获取该后缀。有谁知道一个简单的方法来做到这一点?

Magento can add a suffix that is defined by the user to append onto urls. I want to get that suffix from my code. Does anyone know an easy way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

救赎№ 2024-11-02 11:53:23

如果它存储在配置区域中,则可以像访问任何其他配置值一样访问它,方法是使用定义了 $config_pathMage::getStoreConfig($config_path)在定义它的模块的 system.xml 中。

如果您不确定 $config_path,那么我通常会作弊并检查配置部分中的文本框/下拉列表,查看 id,例如 dev_log_file,并将其翻译为dev/log/file。当有多个 _ 时,您需要使用一些智能:)

If it's stored in the configuration area, then you access it just as you would any other configuration value, by using Mage::getStoreConfig($config_path) where $config_path is defined in the system.xml of the module that defines it.

If you're not sure of the $config_path, then I usually cheat and inspect the textbox/dropdown in the configuration section, take a look at the id, e.g. dev_log_file, and translate it to dev/log/file. You'll need to use some intelligence when there are multiple _ though :)

笑咖 2024-11-02 11:53:23

尼克的回答很好,但这个问题的实际答案是:

$suffix = Mage::helper('catalog/category')->getCategoryUrlSuffix();

Nick's answer is good but the actual answer to this question is:

$suffix = Mage::helper('catalog/category')->getCategoryUrlSuffix();
世态炎凉 2024-11-02 11:53:23

如果我没记错的话,这是代码(因为我不明白您想要的URL想要什么)

<?php
    $currentUrl = $this->helper('core/url')->getCurrentUrl();
    $url_parts = split('[/.-]', $currentUrl); // escape characters should change based your url
    echo $url_parts[0]; //check here
?>

If I am not mistaken, here is the code ( because I don't understand what you want with URL )

<?php
    $currentUrl = $this->helper('core/url')->getCurrentUrl();
    $url_parts = split('[/.-]', $currentUrl); // escape characters should change based your url
    echo $url_parts[0]; //check here
?>
傲娇萝莉攻 2024-11-02 11:53:23

完整产品网址:

$productId = ***;
$productUrl  = Mage::getBaseUrl().Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'url_key', Mage::app()->getStore()).Mage::helper('catalog/product')->getProductUrlSuffix();

complete product url:

$productId = ***;
$productUrl  = Mage::getBaseUrl().Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'url_key', Mage::app()->getStore()).Mage::helper('catalog/product')->getProductUrlSuffix();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文