【发布时间】:2013-07-18 15:06:56
【问题描述】:
我使用的是 CakePHP 2.3
我有两个环境,其中有我的 Web 应用程序。在具有完全相同版本的应用程序的测试环境中(所有文件都相同)我遇到了Form->postLink 方法的问题。
它在 Javascript 控制台上显示此错误:
Uncaught TypeError: Object # has no method 'submit' users:119 点击
比较两种环境生成的 HTML,我可以注意到此方法生成的属性 name 和 id 在同一页面中重复多次(不应该这样)。
这是用于生成这些帖子链接的代码:
foreach($users as $user){
$delete = $this->Form->postLink(__('Delete'), array('action' => 'delete', $user['user_id']), __('Are you sure you want to delete %s?', $user['user_id']));
}
这是生成的有问题的 HTML,如您所见,id 和 name 有重复值:
<!-- link 1 -->
<form action="delete/1/" name="post_51e8019d095f1" id="post_51e8019d095f1" 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 blabla?')) { document.post_51e8019d095f1.submit(); } event.returnValue = false; return false;">Delete</a>
<!-- link 2 -->
<form action="delete/2/" name="post_51e8019d095f1" id="post_51e8019d095f1" 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 blabla22?')) { document.post_51e8019d095f1.submit(); } event.returnValue = false; return false;">Delete</a>
为什么会这样? 它可能与Web服务器的配置有关吗?我没有看到其他解释...
谢谢。
【问题讨论】:
-
我能看到的唯一问题是
postLink()方法中的第二个参数。它应该类似于array('action' => 'delete', $user['User']['user_id'])。 -
@CrisSawfish 不是问题。我正在使用 Oracle 和程序而不是 CakePHP 模型,因此结构不同。
-
postLink() 方法为表单创建了一个唯一的 id,正如您在 source 中看到的那样,它正确地完成了它。我也将它与最新版本的 CakePHP 一起使用。所以它可能在你的
foreach循环中有其他东西。 -
@CrisSawfish 出了点问题,但我不知道是什么。这是循环代码 Cris:pastebin.com/VRe4uaad
-
所以这绝对是不是
postLink()的问题。我刚刚在我的系统中测试了你的循环(开发环境配置),它工作得很好!由于表单 ID 是使用当前微时间创建的(检查 uniqid function),您的 php 设置可能有问题?
标签: cakephp cakephp-2.0 cakephp-2.3