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

后端 未结 4 594
余生分开走
余生分开走 2021-02-08 20:10

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 t

相关标签:
4条回答
  • 2021-02-08 20:46

    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.

    0 讨论(0)
  • 2021-02-08 20:56

    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)
    );
    
    0 讨论(0)
  • 2021-02-08 20:56
    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]);
    
    0 讨论(0)
  • 2021-02-08 20:56

    Yes It's possible to make an image as anchor tag. You just needs to set escape = false for it like below :-

    <?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));
    
    ?>
    
    0 讨论(0)
提交回复
热议问题