我正在使用CakePHP 1.2。我正在尝试使用CakePHP的jQuery Lazy(http://jquery.eisbehr.de/lazy/example_basic-usage)。阅读https://book.cakephp.org/1.2/en/The-Manual/Core-Helpers/HTML.html#image上的文档,它显示了如何
<?php echo $html->image('cake_logo.png', array('alt' => 'CakePHP'))?>
产生以下输出:
<img src="/img/cake_logo.png" alt="CakePHP" />
我需要产生以下输出:
<img class="lazy" data-src="/img/cake_logo.png" />
如何在CakePHP 1.2中使用$html->image()
来做到这一点?问题在于,在语法image(string $path, array $htmlAttributes = array())
中,第一个参数是强制性的,并且在输出中它产生src=...
的{{1}}属性。我需要有一个img
的输出,其中不包含<img... />
属性。如何在CakePHP中使用$ html-> image()实现此目标?
答案 0 :(得分:1)
通过内置的HTML帮助程序,必须先修改标签模板,然后才能实现。因此,如果您需要在所有图像上进行延迟加载,则可以例如将::-webkit-scrollbar {
width: 20px;
}
::-webkit-scrollbar-track {
box-shadow: inset 0 0 5px grey;
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
background: red;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: #b30000;
}
标记模板更改为:
image
但是,这将与使用<img class="lazy" data-src="%s" %s/>
属性冲突。因此,您也可以扩展HTML帮助器并实现自定义class
方法(或其他方法)。这是一个快速且肮脏的示例,应该是很自欺欺人的:
image()
另请参见