CakePHP: image inside link, want to make link point to image location

一笑奈何 提交于 2019-12-19 11:07:24

问题


I have some images inside links that I want to essentially look like this:

<a href="/path/to/img.png"><img src="/path/to/img.png" /></a>

Clicking on the link should load the image it contains. I'm trying to use CakePHP's HTML helper to do this, as follows:

<?php
  echo $html->link(
    $html->image('img.png'),
    'img.png',
    array('escape' => false)
  );
?>

When I do this, however, I get the following code:

<a href="/pages/img.png"><img src="/path/to/img.png" /></a>

Without using absolute URLs, can I make the link's href attribute point to the image's correct location?

Thanks!


回答1:


This should do the trick:

echo $html->image('image.png', array('url' => '/' . IMAGES_URL . 'image.png'));



回答2:


you can also do this in 1.2

echo $html->link(
    $html->image('img.png'),
    'img.png',
    array(),
    null, 
    false
  );

or in 1.3

echo $html->link(
    $html->image('img.png'),
    'img.png',
    array(),
    array( 'escape' => false ),     
  );


来源:https://stackoverflow.com/questions/1878301/cakephp-image-inside-link-want-to-make-link-point-to-image-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!