如何使用cakephp和twitter bootstrap在表单postlink中创建图标

时间:2014-04-10 18:03:26

标签: forms twitter-bootstrap cakephp tags glyphicons

这给了我想要的东西:

<?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)
); ?>

但是当我创建一个表格postLink时,我不知道如何在它前面获取删除图标..

<?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)
); ?>

它给了我<i class="glyphicon glyphicon-remove"></i> Delete

4 个答案:

答案 0 :(得分:12)

您忘记将选项escape添加到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')
);

答案 1 :(得分:5)

使用按钮

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

答案 2 :(得分:2)

试试这个:

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

答案 3 :(得分:0)

以下代码将创建链接按钮,用于删除带有确认框的项目。

$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']
)