0

如何添加这个 CSS:

<div class="alert alert-error">
</div>

到这个 PHP 代码:

<?php echo this->element->error; ?>

他们是“这个”堆栈旁边的“$”不会显示它

我需要它仅在其处于活动状态时才显示。我试过这样做:

<?php if ($element->error != '') :?>
<div class="alert alert-error"> 
<?php echo $element->error?>
</div>
<?php endif;?>

但它不起作用

下面的错误图片:http: //i.imgur.com/EFtdjE5.png

4

2 回答 2

2

尝试创建一个 if else 条件isset

  // if `$this->element->error` is TRUE or SET..
 <?php if(isset($this->element->error)){?>
    <div class="alert alert-error"> 
    <?php echo $this->$element->error;?>
    </div>
    <?php }?>
 // if not it will be just ignored
于 2013-04-04T03:46:18.657 回答
1
<?php if ($this->element->error != '') :?>
    <div class="alert alert-error"><?php echo $this->element->error;?></div>
<?php endif;?>

这行得通。请注意我的代码与问题的区别。感谢@Kaii 的所有时间。

于 2013-04-04T04:34:06.683 回答