CakePHP - 使用$ this-> Html->链接$ this-> Html-> image ....生成ascii而不是实际的HTML [英] CakePHP - using $this->Html->link with $this->Html->image....generating ascii instead of actual HTML

查看:109
本文介绍了CakePHP - 使用$ this-> Html->链接$ this-> Html-> image ....生成ascii而不是实际的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cakephp 2.3.0。我在手册中搜索了相当一段时间,但我还没有找到答案。我试图使用$ this-> Html->链接,以及$ this-> Html-> image。我试图创建点击图像的能力。



这是我的代码集在我的视图ctp:

  echo $ this-> html-> tableCells(
array(
array(
array(
$ this- > Html-> link($ myActivity ['Activity'] ['name'],array('controller'=>'users','action'=>'edit'),array ''')),
array('align'=>'left')),
array($ myActivity ['Activity'] ['status'],array >'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')),


);

下面是上面代码的实际HTML结果。正如你所看到的,生成的HTML显示为ascii版本的引号()和'<'和'>':

 < tr> 
< td align =left>
< a href =/ activities / index.php / users / addtitle => 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 / edittitle = & lt; img src =& quot; /activities/app/webroot/img/pencil.jpg& quot; alt =& quot; Edit& quot; border =& quot; 0& quot; width =& 25& quot; /& gt;< / a>
< / td>
< td>
< img src =/ activities / app / webroot / img / trashcan.jpgalt =Deleteborder =0width =25>
< / td>
< / tr>



下面是我期望的HTML看起来像:

 < tr> 
< td align =left>
< a href =/ activities / index.php / users / addtitle => Running< / a>
< / td>
< td align =left> Live< / td>
< td align =left>无< / td>
< td> 02/18/13< / td>
< td>
< a href =/ activities / index.php / users / edittitle =>
< img src =/ activities / app / webroot / img / pencil.jpgalt =编辑border =0width =25>< / a>
< / td>
< td>
< img src =/ activities / app / webroot / img / trashcan.jpgalt =Deleteborder =0width =25>
< / td>
< / tr>


解决方案

您需要添加 link()调用的选项数组的选项。将其设置为 false ,如下所示:

  echo $ this-> ; Html-> link(
$ this-> Html-> image('mydog.jpg'),'/lol​​.html',array('escape'=> false)
);


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?

Here is my snippet codeset in my view 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 '>':

<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="">&lt;img src=&quot;/activities/app/webroot/img/pencil.jpg&quot; alt=&quot;Edit&quot; border=&quot;0&quot; width=&quot;25&quot; /&gt;</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:

<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>

解决方案

You need to add the escape option to the options array of your link() calls. Set it to false, like this:

echo $this->Html->link(
    $this->Html->image('mydog.jpg'), '/lol.html', array('escape' => false)
);

这篇关于CakePHP - 使用$ this-&gt; Html-&gt;链接$ this-&gt; Html-&gt; image ....生成ascii而不是实际的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆