【问题标题】:Insert an icon into a link with HTMLhelper in CakePHP 3在 CakePHP 3 中使用 HTMLhelper 将图标插入链接
【发布时间】:2017-05-09 13:38:26
【问题描述】:

我想用 CakePHP 的 HTMLhelper 创建的链接中的字体替换文本。

这是可以正常工作的文本版本:

Html->link('View', ['action' => 'view', $menuitem->id], ['title' => __('View'),'class' => 'btn btn-info btn -xs']) ?>

这是我想要完成的一个例子:

Html->link('span with icon go here', ['action' => 'view', $menuitem->id], ['title' => __('View'),'class' => 'btn btn-信息 btn-xs']) ?>

任何想法都会有所帮助。谢谢!

【问题讨论】:

    标签: cakephp-3.0


    【解决方案1】:

    使用escape 选项,例如:

    <?= $this->Html->link(
        '<span class="fa fa-search"></span><span class="sr-only">' . __('View') . '</span>',
        ['action' => 'view', $menuitem->id],
        ['escape' => false, 'title' => __('View'), 'class' => 'btn btn-info btn-xs']
    ) ?>
    

    来自the docs

    $title 中的 HTML 特殊字符将被转换为 HTML 实体。 要禁用此转换,请将转义选项设置为 false $options 数组。

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

    【讨论】:

      【解决方案2】:
      <?= $this->Html->link('' ,['id' => 'logo',
      'controller' => 'Pages', 'action' => 'display', 'home'], 
      ['class' => 'navbar-brand page-scroll']) ?>
      

      我只是在css中设置了图片,这样显示

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多