在CakePHP 3中使用FormHelper创建的postLink需要一些帮助。正常的postLink可以正常工作:
<?= $this->Form->postLink(__('Delete'),
['action' => 'delete', $member->id],
['confirm' => __('Are you sure, you want to delete {0}?', $member->name)]) ?>
但是当我尝试使用font-awesome图标/ i-tag而不是文本链接时,确认消息不再显示。图标本身显示正确,操作仍然正常,只是消息无法正常工作。
我使用以下帖子寻求帮助,但答案中的示例对我不起作用:
CakePHP equivalent of html code
我尝试了这两种方法:
<?= $this->Form->postLink('<i class="fa fa-trash"></i> ',
['action' => 'delete', $member->id],
['escape' => false],
['confirm' => __('Are you sure, you want to delete {0}?', $member->name)]) ?>
<?= $this->Form->postLink(
$this->Html->tag('i', '', ['class' => 'fa fa-trash']),
['action' => 'edit', $member->id],
['escape' => false],
['confirm' => __('Are you sure you want to delete {0}?', $member->name)]); ?>
我仍然是CakePHP的新手,并试图在书中查看,但这对我没有帮助。我也尝试了上面的SO链接中显示的确切语法,这似乎适用于其他一些......但确认消息仍然不适合我。
我在这里做错了什么?
答案 0 :(得分:2)
escape
和confirm
选项应位于同一个数组中。函数postLink()
如下所示:
postLink(string $title, mixed $url = null, array $options =[])
所以工作代码将是:
<?= $this->Form->postLink('<i class="fa fa-trash"></i> ',
['action' => 'delete', $member->id],
[
'escape' => false,
'confirm' => __('Are you sure, you want to delete {0}?', $member->name)
]
) ?>