【问题标题】:Html-helper postLink in CakePHPCakePHP 中的 Html-helper postLink
【发布时间】:2012-04-01 10:15:51
【问题描述】:

我正在尝试创建类似的东西,因为我在我的一个管理视图中完成了它:

<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>

如果我使用完全相同的代码来生成它,为什么会发生这种情况? 谢谢。

【问题讨论】:

  • 您确定$user 变量已设置并包含您认为的功能吗?

标签: cakephp post hyperlink html-helper cakephp-2.0


【解决方案1】:

首先。检查 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'])); 
?>

【讨论】:

    【解决方案2】:

    您还没有创建表单本身,所以本质上您使用的是没有表单的输入字段。

    echo $this->Form->create();
    

    【讨论】:

    • 这实际上是错误的。 $this->Form->postLink() 不必在表单中。实际上它不能在表单内(参见github.com/cakephp/cakephp/blob/master/lib/Cake/View/Helper/…)。
    • 这太具有误导性了……正如@tinytiger 指出的那样,您不能在表单中包含表单。这会破坏一切。
    • 这个答案是绝对错误的,应该删除。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    相关资源
    最近更新 更多