Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakePHP formHelper postLink image

Tags:

php

cakephp

I want to output an image with a hyperlink wrapped around it instead of just a text hyperlink using cakePHP's formHelper::postLink function.

Does anyone know how to do this? I tried multiple things but couldn't get it working.

<?php echo $this->Form->postLink(
    'Delete',
    array('action' => 'delete', $country['Country']['id']),
    array('confirm' => __('Are you sure you want to delete ').$country['Country']['name'].'?')
)?>

So instead of 'Delete' I want to display an image.

like image 821
Boyd Avatar asked Dec 16 '22 07:12

Boyd


2 Answers

Here's what works for me.

echo $this->Form->postLink(
  $this->Html->image('icn_trash.png', array('alt' => __('Effacer'))), //le image
  array('action' => 'delete', $artist['Artist']['id']), //le url
  array('escape' => false), //le escape
  __('Êtes-vous sûr de vouloir effacer artiste #%s?', $artist['Artist']['id']) //le confirm
); //le voila
like image 144
bnadeau Avatar answered Dec 18 '22 21:12

bnadeau


Try this :

echo $this->Form->postLink(
    $this->Html->image('delete.png',
       array("alt" => __('Delete'), "title" => __('Delete'))), 
    array('action' => 'delete', $items['Item']['id']), 
    array('escape' => false, 'confirm' => __('Are you sure?')) 
);
like image 25
adc Avatar answered Dec 18 '22 19:12

adc