如何在 cakephp 3 的标签内添加 <i> 和 <span> 标签?

How to add <i> and <span> tag inside a tag in cakephp 3?

我的 html 代码如下:

<a  href="/patients/index" class="m-menu__link ">
    <i class="m-menu__link-bullet m-menu__link-bullet--dot">
        <span></span>
    </i>
    <span class="m-menu__link-text">
        Add Medicines
    </span>
</a>

我想在 cakephp 3 中使用 HtmlHelper 来转换它。

以下代码用于在 cakephp 3 的超链接内添加和标记

<?php echo $this->Html->link(
       $this->Html->tag("i", "<span></span>",array("class" => "m-menu__link-bullet m-menu__link-bullet--dot")).$this->Html->tag("span", "Add Medicine", 
        array("class" => "m-menu__link-text")),
       ["controller"=>"Medicines", "action"=>"index"],
       ["class"=>"m-menu__link",
        "escape"=>false]
       );
   ?> 

您想在 link() 方法中使用 'escape' => false 参数。这会阻止 Cake 转义标记:-

<?= $this->Html->link(
    '<i class="m-menu__link-bullet m-menu__link-bullet--dot"><span></span></i><span class="m-menu__link-text">' . h('Add Medicines') . '</span>', 
    '/patients/index', 
    [
        'escape' => false, 
        'class' => 'm-menu__link'
    ]
) ?>

重要的是要记住仍然使用 h() 转义任何用户生成的内容。我在上面的示例中通过转义 'Add Medicines' 来展示了这一点,但是如果这是硬编码的,则不需要将其包装在 h() 方法中。