Using image as link in CAKEPHP and html code escape problem
Following Code is required for that:
echo $this->Html->image("your_img.png", array( 'url' => array('controller' => 'some_controller', 'action' => 'display') ));
Will output:
<a href="/some_controller/display"> <img src="/img/your_img.png" /> </a>
Remember: When you want to give image height width as well inside link do it as:
<?php echo $this->Html->link( $this->Html->image("go.png", array( 'alt' => "Go","height"=>30,"width"=>30) ), "/login/codes/$row->id", array( 'title' => "Start Session $row->code", 'escape' => false) ); ?>
Please don’t forget to add ‘escape’=>false in last params array, else you will get html code for image;
<img src="/is/img/go.png" alt="Go" height="30" width="30" /> // code from my application
Leave a Reply