【问题标题】:How to create icon inside form postlink with cakephp and twitter bootstrap如何使用 cakephp 和 twitter bootstrap 在表单 postlink 中创建图标
【发布时间】:2014-04-10 18:03:26
【问题描述】:

这给了我想要的:

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

它给了我&lt;i class="glyphicon glyphicon-remove"&gt;&lt;/i&gt; Delete

【问题讨论】:

  • 只是对您的用户体验进行了一点更新。您在询问用户是否要删除具有特定 ID 的评论,您相信他们知道他们评论的 ID 是什么吗?我认为最好问“您确定要删除以下评论吗?”然后可能添加前 50 个字符左右?或者,如果它是管理员操作,则可能包括发布它的用户的名称。只是一点头;-)
  • 谢谢,确实最好不要使用comment_id UX。再次感谢!

标签: forms twitter-bootstrap cakephp tags glyphicons


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    使用按钮

                          <?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】:

      试试这个:

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

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          猜你喜欢
          • 2014-12-06
          • 1970-01-01
          • 2018-07-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-11-10
          相关资源
          最近更新 更多