Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP - using $this->Html->link with $this->Html->image....generating ascii instead of actual HTML

Tags:

html

cakephp

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>
like image 588
Kevin Avatar asked Feb 21 '13 16:02

Kevin


1 Answers

echo $this->Html->image('imagename',array('alt'=>'myimage','class'=>'img-responsive'));

This is normal image 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]);
like image 62
Pooja Avatar answered Nov 10 '22 01:11

Pooja