CakePHP formHelper postLink image

I want to display an image with a hyperlink wrapped around it, and not just a text hyperlink, using the cakePHP formHelper :: postLink function.

Does anyone know how to do this? I tried a few things, but could not get it to work.

<?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 the image.

+4
source share
6 answers

Here is 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 
+9
source

Try the following:

 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?')) ); 
+4
source

If I understand your question correctly, I don’t think you want to use $this->Form->postLink

I think this page is exactly what you need: http://book.cakephp.org/view/1441/image

$this->Html->image is used to create the $this->Html->image , and then you can pass the URL through one of the parameters to indicate the surrounding binding.

+2
source

You can wrap the image inside the link element, but you need to set the escape option to false, for example:

 echo $this->Html->link( $this->Html->image('your_image_here.jpg', array( 'alt' => 'Alternative Text for your image', 'title' => 'Optional tooltip text for your image' ), array( 'controller' => 'YourController', 'action' => 'someAction' ), array( 'escape' => false // Add this to avoid Cake from printing the img HTML code instead of the actual image ) ); 

That should do the trick.

+1
source
 echo $this->Html->link( $this->Html->image("recipes/6.jpg", array("alt" => "Brownies")), array( 'controller' => 'recipes', 'action' => 'view', 'id' => 6, 'comments' => false ) ) 
0
source

function delete_image () {

  if ($this->Session->read('Auth.User.id')) { $this->User->id = $this->Session->read('Auth.User.id'); $this->User->updateAll( array('User.image' => "''"), array('User.id' => $this->User->id) ); $this->Session->setFlash('The image has been deleted.'); $this->redirect(array('action' => 'profile')); } } 
-4
source

Source: https://habr.com/ru/post/1380912/


All Articles