【问题标题】:CakePHP - Best approach to add HTML content inside CakePHP form helper link?CakePHP - 在 CakePHP 表单帮助链接中添加 HTML 内容的最佳方法?
【发布时间】:2019-04-14 16:44:54
【问题描述】:

我正在尝试在 CakePHP 表单助手链接生成器代码中添加一个图标。我在stackoverflow上尝试了几个可用的选项。但似乎没有任何效果。

这是我当前的代码 - 我尝试了这个方法Link

<?= $this->Html->link(('View'), ['action' => 'view', $group->id] , array('class' => 'dropdown-item' , 'between' => '<i class="la la-eye"></i>' , 'after' => '')) ?>

此方法在锚标记内创建属性。这不是我想要实现的。

我正在努力实现这一目标。

<a href="groups/view/1" class="dropdown-item"><i class="la la-pencil"></i> Edit</a>

我正在使用 CakePHP 3.7.4

【问题讨论】:

    标签: html cakephp cakephp-3.0


    【解决方案1】:

    阅读https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-links

    echo $this->Html->link(
        $this->Html->image("recipes/6.jpg", ["alt" => "Brownies"]),
        "recipes/view/6",
        ['escape' => false]
    );
    

    将输出:

    <a href="/recipes/view/6" title="hi &quot;howdy&quot;">
        <img src="/img/recipes/6.jpg" alt="Brownies" />
    </a>
    

    在你的情况下:

    echo $this->Html->link(
        "<i class="la la-pencil"></i> Edit",
        "recipes/view/6",
        ['escape' => false]
    );
    

    【讨论】:

    • 嗨@salines 谢谢你的帮助。代码完美运行。不得不稍微调整一下。 = $this->Html->link(" 查看", ['action' => 'view', $group->id], ['逃脱' => 假,'类' => '下拉项目']); ?>
    猜你喜欢
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    相关资源
    最近更新 更多