CakePHP - 使用 $this->Html->link with $this->Html->image....生成 ascii 而不是实际的 HTML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15007396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CakePHP - using $this->Html->link with $this->Html->image....generating ascii instead of actual HTML
提问by Kevin
I'm using cakephp 2.3.0. I searched in the manual for quite awhile, but I haven't found the answer. I'm trying to use $this->Html->link, along with $this->Html->image. I'm trying to create the ability to click on an image. Any ideas as to why the ascii rendering of quotes is being generated?
我正在使用 cakephp 2.3.0。我在手册中搜索了很长时间,但我还没有找到答案。我正在尝试使用 $this->Html->link,以及 $this->Html->image。我正在尝试创建单击图像的能力。关于为什么生成引号的 ascii 渲染的任何想法?
Here is my snippet codeset in my view ctp:
这是我的视图 ctp 中的代码段代码集:
echo $this->html->tableCells(
array(
array(
array (
$this->Html->link($myActivity['Activity']['name'], array('controller' => 'users', 'action' => 'edit'), array('title' => '')),
array('align' => 'left')),
array ($myActivity['Activity']['status'], array('align' => 'left')),
array ($myActivity['Activity']['any_messages'], array('align' => 'left')),
$date2,
array ($this->Html->link(
$this->Html->image('pencil.jpg', array('alt' => 'Edit', 'border' => '0', 'width' => '25')),
array('controller' => 'users', 'action' => 'add'), array('title' => ''))
),
$this->Html->image('trashcan.jpg', array('alt' => 'Delete', 'border' => '0', 'width' => '25')),
$this->Html->image('copy.png', array('alt' => 'Copy', 'border' => '0', 'width' => '25')),
)
)
);
Below is the actual HTML result of the code above. As you can see, the generated HTML is showing ascii version of quotes (") and '<' and '>':
下面是上面代码的实际 HTML 结果。如您所见,生成的 HTML 显示了引号 (") 和 '<' 和 '>' 的 ascii 版本:
<tr>
<td align="left">
<a href="/activities/index.php/users/add" title="">Running</a>
</td>
<td align="left">Live</td>
<td align="left">no</td>
<td>02/18/13</td>
<td>
<a href="/activities/index.php/users/edit" title=""><img src="/activities/app/webroot/img/pencil.jpg" alt="Edit" border="0" width="25" /></a>
</td>
<td>
<img src="/activities/app/webroot/img/trashcan.jpg" alt="Delete" border="0" width="25">
</td>
</tr>
Below is what I would expect the HTML to look like:
下面是我希望 HTML 的样子:
<tr>
<td align="left">
<a href="/activities/index.php/users/add" title="">Running</a>
</td>
<td align="left">Live</td>
<td align="left">no</td>
<td>02/18/13</td>
<td>
<a href="/activities/index.php/users/edit" title="">
<img src="/activities/app/webroot/img/pencil.jpg" alt="Edit" border="0" width="25"></a>
</td>
<td>
<img src="/activities/app/webroot/img/trashcan.jpg" alt="Delete" border="0" width="25">
</td>
</tr>
回答by Matt Cain
You need to add the escape
option to the options array of your link()
calls. Set it to false
, like this:
您需要将该escape
选项添加到您link()
调用的选项数组中。将其设置为false
,如下所示:
echo $this->Html->link(
$this->Html->image('mydog.jpg'), '/lol.html', array('escape' => false)
);
回答by Ravi Roshan
Yes It's possible to make an image as anchor tag. You just needs to set escape = false for it like below :-
是的 可以将图像制作为锚标记。您只需要为它设置 escape = false ,如下所示:-
<?php
$thumb_img = $this->Html->image('yourimage.png',array('alt'=>'yoursite.com','class'=>'yourclass'));
echo $this->Html->link( $thumb_img, array('controller'=>'yourcontroller','action'=>'youraction'), array('escape'=>false));
?>
回答by Pooja
echo $this->Html->image('imagename',array('alt'=>'myimage','class'=>'img-responsive'));
This is normalimage without any link, now to wrap it with link tag use
这是没有任何链接的普通图像,现在用链接标签包装它
echo $this->Html->link($this->Html->image('imagename',array('alt'=>'myimage', 'title'=>'myimage','class'=>'img-responsive')), [
'controller' => 'controllerName',
'action' => 'actionName',
'id' => $value['id'], //if any parameters are passed
],['escape' => false]);
Similarly you can assign the image tag to a variable and use it
同样,您可以将图像标签分配给变量并使用它
$myImageVar = $this->Html->image('imagename',array('alt'=>'myimage','class'=>'img-responsive'));
echo $this->Html->link($myImageVar, [
'controller' => 'controllerName',
'action' => 'actionName',
'id' => $value['id'], //if any parameters are passed
],['escape' => false]);
回答by sabin
Try this :
尝试这个 :
echo $this->Html->link('', array(
'controller' => 'Mycont',
'action' => 'deletepic',
$id
), array(
'confirm' => 'Are you sure you want to delete the image?',
'class' => 'deleteImg'
));
I have linked image to in class deleteImg.
我已将图像链接到类中的 deleteImg。