我正在使用Magento,我想显示一个div,这取决于我是否在特定视图中。我使用以下方法:
<?php
$url1 = (string)$this->getBaseUrl()."home_tienda";
$url2 = (string)$this->getUrl('*/*/*',array('_current'=>true, '_use_rewrite'=>true));
?>
如果我键入 $url 1 和 $url 2 的"var_dump",我会得到以下内容:
string(28) "http://127.0.0.1/home_tienda"
string(37) "http://127.0.0.1/home_tienda"
好吧,我已经尝试过这个:
<?php if (strcmp($url1,$url2)==0):?>
<div class="clsbanner"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_banner')->toHtml(); ?></div>
<?php endif?>
我也试过这个:
<?php if ($url1==$url2):?>
<div class="clsbanner"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_banner')->toHtml(); ?></div>
<?php endif?>
在这两个中,我都获得了 false,所以我的div 没有显示,我需要显示它
请使用===
运算符重试strcmp()
和/或stricmp()
。另一个有用的工具是 stripos()
,它从您的 URL 比较中返回 0,但如果找不到字符串,则会返回 FALSE。
0 == FALSE
测试相同...
然而
0 === FALSE
将捕获您正在寻找的条件===
也与数据类型匹配。