Question

This gives me what I want:

<?php echo $this->Html->link(
   $this->Html->tag('i', '', array('class' => 'glyphicon glyphicon-edit')) . " Edit",
   array('action' => 'edit', $comment['Comment']['comment_id']),
   array('class' => 'btn btn-mini', 'escape' => false)
); ?>

But when I create a Form postLink I don't know how to get the remove icon in front of it..

<?php echo $this->Form->postLink(
   $this->Html->tag('i', '', array('class' => 'glyphicon glyphicon-remove')) . " Delete",
   array('action' => 'delete', $comment['Comment']['comment_id']), null, __('Are you sure you want to delete # %s?', $comment['Comment']['comment_id']),
   array('class' => 'btn btn-mini', 'escape' => false)
); ?>

It gives me <i class="glyphicon glyphicon-remove"></i> Delete

Was it helpful?

Solution

You forgot add option escape to false

echo $this->Form->postLink(
   $this->Html->tag('i', '', array('class' => 'glyphicon glyphicon-remove')). " Delete",
        array('action' => 'delete', $comment['Comment']['comment_id']),
        array('escape'=>false),
    __('Are you sure you want to delete # %s?', $comment['Comment']['comment_id']),
   array('class' => 'btn btn-mini')
);

OTHER TIPS

using a button

                      <?php     echo $this->Form->postLink(
                '<button class="btn btn-danger">
                     <i class="icon-trash icon-white"></i>
                 </button>',
                array(
                      'action'   => 'delete', $post['Post']['id']
                      ),
                array(
                      'class'    => 'tip',
                      'escape'   => false,
                      'confirm'  => 'Are you sure ?'
                     ));
                     ?>

Try this:

<?php
 echo $this->Form->postLink(
                    'Delete',
                    array('controller'=>'Comments',
                      'class'=>'glyphicon glyphicon-remove','action' => 'delete',$comment['id']),
                    array('confirm' => 'Are you sure?')
 );
?> 

The below code will create Link Button for deleting Items with a Confirmation box.

$this->Form->postLink( 'Delete Item',
    ['action' => 'delete', 'paramId' => $item->id ],
    ['confirm' => __('Are you sure you want to delete this Item?'), 'class'=> 'btn btn-outline-danger']
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top