我正在使用magento,我希望显示一个div,具体取决于我是否在特定视图中。我使用以下内容:
<?php
$url1 = (string)$this->getBaseUrl()."home_tienda";
$url2 = (string)$this->getUrl('*/*/*',array('_current'=>true, '_use_rewrite'=>true));
?>
如果我输入$ url1和$ url2的“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?>
在我获得的都是假的,所以我的div没有显示,我需要它显示
答案 0 :(得分:2)
请使用strcmp()
运营商重试stricmp()
和/或===
。另一个有用的工具是stripos()
,它从您的URL比较中返回0,但如果找不到string则返回FALSE。
0 == FALSE
测试相同......
然而
0 === FALSE
会抓住您要查找的条件,因为===
也匹配数据类型。