【发布时间】:2014-10-01 06:24:49
【问题描述】:
我正在尝试在 Magento 中获取当前 URL,如果我当前在该页面上,则显示一些内容。到目前为止,这就是我所做的并且成功了。
<?php
$currentUrl = $this->helper('core/url')->getCurrentUrl();
?>
<?php if($currentUrl === 'http://powerplantv2.jehzlau.net/blog') { ?>I am in the blog page<?php } ?>
但是我不想硬编码源代码中的URL,因为如果我转移到另一个服务器,我需要再次修改phtml文件。
我尝试了我在网上找到的所有方法,但没有奏效。我希望这里的一些 Magento 专家可以启发我我做错了什么。 :(
【问题讨论】:
-
无论如何,我能够使用 substr 解决我自己的问题。我注意到 blogUrl 最后有一个 /,所以我使用 substr 删除了它,因此这段代码现在可以立即在特定页面上显示某些内容。 :D
codehelper('core/url')->getCurrentUrl(); $blogUrl = $this->getUrl('blog'); $blogfixedurl = substr($blogUrl, 0, -1); ?> 您目前在博客页面code不过如果有人有更好的解决方案,欢迎回答。我认为我的代码可以缩短。 :D