【问题标题】:How do I add attributes to a link made with the image method from the HTMLHelper in CakePHP?如何将属性添加到使用 CakePHP 中 HTMLHelper 中的 image 方法创建的链接?
【发布时间】:2010-11-24 04:48:08
【问题描述】:

我正在使用 CakePHP。

这行代码会生成一个<img>标签:

$html->image('image.png', array('alt', 'Alternative text'));

这将产生相同的东西,但它会使图像可点击:

$html->image('image.png', array('alt' => 'Alternative text', 'url' => 'http://www.example.com'));

目前我了解,但是如果我想给<a> 标签添加属性,我该怎么办。

这样做:

$html->image('image.png', array('alt' => 'Alternative text', 'url' => 'http://www.example.com/', 'class' => 'aClass'));

将属性添加到<img> 而不是<a>。输出是这样的:

<a href="http://www.example.com/">
    <img src="image.png" alt="Alternative text" class="aClass" />
</a>

但我想要这样的东西:

<a href="http://www.example.com/" class="aClasse">
    <img src="image.png" alt="Alternative text" />
</a>

我尝试使用$html-&gt;image() 作为第一个参数,但它不起作用。

有什么想法吗?

【问题讨论】:

    标签: php cakephp html-helper


    【解决方案1】:

    是的,您需要使用 HTML 帮助程序 link 方法并告诉它不要转义标题,这是默认情况下通过添加 'escape' =&gt; false 参数执行的操作。请阅读手册,那里有解释:http://book.cakephp.org/view/1442/link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 2015-01-06
      相关资源
      最近更新 更多