我正在尝试创建类似这样的内容,因为我已经在我的一个管理员视图中完成了它:
<td class="actions">
<form action="/users/delete/26" name="post_4f7825317b6b0" id="post_4f7825317b6b0" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST">
</form>
<a href="#" onclick="if (confirm('Are you sure you want to delete # 26?')) { document.post_4f7825317b6b0.submit(); } event.returnValue = false; return false;">
Delete
</a>
</td>
使用此:
<?php
echo $this->Form->postLink(__('Delete'), array(
'action' => 'delete',
$user['User']['id']),
null,
__('Are you sure you want to delete # %s?', $user['User']['id']));
?>
我在另一个视图中使用相同的代码尝试它,我不知道为什么我只能得到这个:
<input type="hidden" name="_method" value="POST">
<a href="#" onclick="if (confirm('Are you sure you want to delete # %s?')) { document.post_4f782a44e9784.submit(); } event.returnValue = false; return false;">
Delete
</a>
如果我使用完全相同的代码生成它,为什么会发生这种情况? 感谢。
答案 0 :(得分:0)
首先。检查CakePHP版本。
<?php
echo $this->Form->postLink(__('Delete'), array(
'action' => 'delete',
$user['User']['id']),
['inline' => true],
__('Are you sure you want to delete # %s?', $user['User']['id']));
?>
答案 1 :(得分:-4)
您尚未创建表单本身,因此基本上您使用的是没有表单的输入字段。
echo $this->Form->create();