CakePHP中的Html帮助程序postLink
我正在尝试创建类似这样的东西,因为我已经在我的一个管理视图中创建了它:CakePHP中的Html帮助程序postLink,cakephp,post,hyperlink,html-helper,cakephp-2.0,Cakephp,Post,Hyperlink,Html Helper,Cakephp 2.0,我正在尝试创建类似这样的东西,因为我已经在我的一个管理视图中创建了它: <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
<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>
如果我使用完全相同的代码生成它,为什么会发生这种情况?
谢谢。您还没有创建表单本身,因此实际上您使用的是没有表单的输入字段
echo $this->Form->create();
首先。检查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']));
?>
您确定设置了$user
变量并包含您认为它的功能吗?这实际上是错误的$此->表单->postLink()不必位于表单内部。实际上它不可能在表单中(请参阅)。这太误导人了。。。正如@tinytiger指出的,表单中不能有表单。这将破坏一切。这个答案是绝对错误的,应该删除。