如果数据库字段'types'中没有id#,我将尝试不显示文本。如果数据库中有项目"id",则信息将显示为"Type:item Type",这很好。
问题是,当数据库中并没有id#时,因为并没有选择项目类型,所以在页面上显示"类型:",而我不想显示任何内容。
显示文本的代码如下。
<? if($this->params->get('item_types', 1) == 1 || ($this->params->get('item_types', 1) == 2 && !empty($this->item->types))){ ?>
<strong class="label_detailed_item"><?php echo JText::_( 'Type' ); ?></strong> <span class="value_detailed_item"><?php echo implode(" / ",$this->item->types); ?></span><br />
<? } ?>
我已经尝试更改以下使用,但文本仍然显示
<?php if ( !empty($this->item->types)) echo JText::_( 'Type' ); ?>
如有任何帮助,我们将不胜感激。
$this->项类型是否可能包含空格字符。这将导致empty()返回FALSE
如果您正在查找一个Id,而该Id始终是整数,请强制转换为整数。
<?php if ( !empty((integer)$this->item->types)) echo JText::_( 'Type' ); ?>