【问题标题】:End span tag in cake php using Html helper使用 Html 助手在蛋糕 php 中结束 span 标签
【发布时间】:2012-02-22 09:55:02
【问题描述】:

如何在 cake php 中结束标签

在 cake 教程中给出了下面的 span 标签将由 html helper 形成,当 text 为 null 时。

<?php echo $this->Html->tag('span', null, array('class' => 'welcome'));?>
//Output
<span class="welcome">

但是,这里没有关于结束 span 标签的想法。如何给它 html helper

<span class="welcome">
    //inner elements
</span>

cake php html helper 中是否有任何东西可以关闭任何元素标签,例如

<?php echo $this->Html->tag('span', 'close') ?>

将输出为

</span> . 

【问题讨论】:

    标签: cakephp cakephp-1.3 html-helper


    【解决方案1】:

    您也可以这样做:

    <?php
    echo $html->tag("span", null);
    ... whatever ...
    echo $html->tag("/span", null);
    ?>
    

    【讨论】:

      【解决方案2】:

      在调用tag 方法时,您必须为第二个参数提供一个空字符串"",而不是null。否则,它只是根据API docs打印开始标签。

      【讨论】:

      • 我知道&lt;?php echo $this-&gt;Html-&gt;tag('span', '', array('class' =&gt; 'welcome'));?&gt; 这个作品。但我想知道文本中给出 null 的情况。
      • 您可以使用三元运算符:&lt;?php echo $this-&gt;Html-&gt;tag('span', $text ?: '', array('class' =&gt; 'welcome'));?&gt; 如果 $text 的计算结果为 true,则使用 $text 的值,否则使用空字符串。
      • 有没有像&lt;?php echo $this-&gt;Html-&gt;tag('span', 'close') ?&gt;这样的东西会输出为&lt;/span&gt;
      • 没有,据我所知没有这个功能。
      猜你喜欢
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 2018-10-04
      • 2017-05-10
      • 1970-01-01
      • 1970-01-01
      • 2014-10-24
      • 1970-01-01
      相关资源
      最近更新 更多