为什么尖括号在我的链接中被转义?

sco*_*ott 0 php cakephp

我正在生成图像的缩略图,我想将缩略图用作链接.我有以下代码

$img = $thumbnail->show($options, $tag_options);
echo $this->Html->image("thumbs/".$img);
echo $this->Html->link($this->Html->image("thumbs/".$img),array('controller'=>'images', 'action'=>'view', $image['Image']['id']));
Run Code Online (Sandbox Code Playgroud)

第一个echo语句正常工作并显示图像.第二个显示一个看起来像这样的链接

<img src="/app/webroot/img/thumbs/fa741043357d4bf1ca39a58edf351d2a.JPG" alt="" />
Run Code Online (Sandbox Code Playgroud)

现在,链接正常工作,因为它占用了该图像的视图页面,但它没有像我期望的那样显示图像.当我查看页面源时,链接如下所示:

<a href="/index.php/images/view/9">&lt;img src=&quot;/app/webroot/img/thumbs/fa741043357d4bf1ca39a58edf351d2a.JPG&quot; alt=&quot;&quot; /&gt;</a>
Run Code Online (Sandbox Code Playgroud)

我注意到img标签上的尖括号被转义了.我究竟做错了什么?

Ros*_*oss 6

出于安全原因,title默认情况下,在使用该link 方法时,HTML实体会在默认情况下进行转义.

您有两种选择:

image方法可以url作为参数.

echo $this->Html->image('thumbs/' . $img, array('url'=> 
                                               array('controller'=>'images', 
                                                     'action'=>'view', 
                                                      $image['Image']['id'])
                                               )
                        );
Run Code Online (Sandbox Code Playgroud)

或者可以使用link的方法和关闭逸出,在第三参数(在这里可以设置title,id,class等等)

echo $this->Html->link($this->Html->image("thumbs/".$img),
                        array('controller'=>'images', 
                              'action'=>'view', $image['Image']['id']),
                        array('escape'=>false, 'class'=>'example') // here
                      );
Run Code Online (Sandbox Code Playgroud)