【发布时间】:2020-09-11 02:07:04
【问题描述】:
我正在尝试在搜索块中显示来自 Concrete5 社区商店的产品页面的 $attributevalue,如果为空则隐藏,如果结果不是产品页面,则显示其他值。一切正常,除非 productpage 的属性为空。它要显示的是:“无属性数据”。它现在显示没有数据的列表。
我不是程序员,不知道是不是出错了。是否与结果为 NULL 或 0 有关?
<?php
$product = \Concrete\Package\CommunityStore\Src\CommunityStore\Product\Product::getByCollectionID($r->getCollectionID());
if ($product && (strlen(trim($attributevalue)) >= 0)){
$attributevalue = $product->getAttribute('artikelnummer');?>
<ul class="searchlist">
<li><span>Artikel nr.:</span> <?php echo $attributevalue ; ?></li>
</ul>
<?php }
elseif ($product && (strlen(trim($attributevalue)) == 0)){
echo 'no attribute data';
}
else {
echo 'no productpage';
}
?>
【问题讨论】:
-
去掉=操作符,strlen(trim($attributevalue)) >= 0) 中不能有零和大于零的长度来为$attributevalue添加值。
-
如果上述解决方案不起作用,请先尝试将
$attributeValue转换为字符串(如trim((string) $attributeValue)),然后再进行修剪。 -
删除 = 操作符就行了。
标签: php if-statement search echo concrete5