How to create icon inside form postlink with cakephp and twitter bootstrap

匆匆过客 提交于 2019-12-06 11:39:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!