cakePHP 3.0 and bootstrap glyphicons

99封情书 提交于 2019-12-04 06:55:21

问题


I want to add glyphicons instead of text in my index, add, edit views.

This works in the index.ctp

<?= $this->Html->link(__('<i class="glyphicon glyphicon-pencil"></i>'), ['action' => 'edit', $user->user_id], array('escape' => false)) ?>

But when I do it for the delete action it shows me the glyphicon but it doesn't give me the 'Are you sure you want to delete the user?' anymore

<?= $this->Form->postLink(__('<i class="glyphicon glyphicon-minus"></i>'), ['action' => 'delete', $user->user_id], array('escape' => false), ['confirm' => __('Are you sure you want to delete {0}?', $user->username)]) ?>

In the view.ctp it breaks the code that comes after so the content that comes after isn't shown. (in this example that's the content after the glyphicon-pencil. The glyphicon-pencil itself isn't shown as well.

<?= $this->Html->link(__('<i class="glyphicon glyphicon-pencil'), ['action' => 'edit', $user->user_id], ['escape' => false]) ?> 

回答1:


Take a closer look at the arguments that you are passing, you are passing 4, where the method only accepts 3, ie the confirm option is not passed in the actual options argument.

Proper formatting helps a lot to spot such mistakes.

<?=
$this->Form->postLink(
    __('<i class="glyphicon glyphicon-minus"></i>'),
    [
        'action' => 'delete',
        $user->user_id
    ],
    [
        'escape' => false,
        'confirm' => __('Are you sure you want to delete {0}?', $user->username)
    ]
)
?>

And your FormHelper::link() example is missing a closing double quote for the <i> elements class attribute, as well as a closing tag for the element itself

'<i class="glyphicon glyphicon-pencil"></i>'

You need to pay more attention to the details, these problem where really really simple and easy to avoid.



来源:https://stackoverflow.com/questions/29703597/cakephp-3-0-and-bootstrap-glyphicons

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