cakePHP 3.0 和 bootstrap 字形

cakePHP 3.0 and bootstrap glyphicons

我想在我的索引、添加、编辑视图中添加字形而不是文本。

这适用于 index.ctp

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

但是当我执行删除操作时,它显示了字形图标,但它不再给我 'Are you sure you want to delete the user?'

<?= $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)]) ?>

在 view.ctp 中,它破坏了后面的代码,因此后面的内容不会显示。 (在这个例子中是 glyphicon-pencil 之后的内容。glyphicon-pencil 本身也没有显示。

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

仔细看看您传递的参数,您传递的是 4,其中该方法只接受 3,即 confirm 选项未在实际选项参数中传递。

正确的格式有助于发现此类错误。

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

并且您的 FormHelper::link() 示例缺少 <i> 元素 class 属性的结束双引号,以及元素本身的结束标记:

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

您可能还想使用 escapeTitle 而不是 escape,以避免禁用属性转义。