问题
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
回答1:
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')
);
回答2:
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 ?'
));
?>
回答3:
Try this:
<?php
echo $this->Form->postLink(
' Delete',
array('controller'=>'Comments',
'class'=>'glyphicon glyphicon-remove','action' => 'delete',$comment['id']),
array('confirm' => 'Are you sure?');
?>
来源:https://stackoverflow.com/questions/22995651/how-to-create-icon-inside-form-postlink-with-cakephp-and-twitter-bootstrap