如何在 Yii 的 chtml::image htmloptions 中添加非 HTML 属性


How to add non HTML attribute in Yii's chtml::image htmloptions

我正在尝试在 Yii CHTML::image($url, $alt, $htmlOptions)的 htmlOptions 数组中添加非 HTML 属性,但在渲染页面中没有添加这些属性。

基本上我想使用延迟加载图像,它需要在'data-origional'中存储原始图像网址,并在SRC标签中存储占位符。 属性。由于某些原因,我无法在代码中使用直接 HTML <img /> 标记。

谢谢大家的任何建议。

这段代码工作正常:

echo CHtml::image('http://google.com/images/srpr/logo3w.png', '', array(
    'data-original' => 'original',
    'another-attribute' => 'bla-bla-bla',
));

它返回:

<img 
     alt="" src="http://google.com/images/srpr/logo3w.png"
     another-attribute="bla-bla-bla"
     data-original="original"
>