【问题标题】:Disabling escape in FormHelper::postLink() breaks alert confirmation在 FormHelper::postLink() 中禁用转义会中断警报确认
【发布时间】:2013-04-28 05:31:17
【问题描述】:

当我尝试在 postlink 帮助程序中将 escape 设置为 false 时,JavaScript 警报似乎在 Chrome 中中断,不知道为什么因为我没有收到任何控制台错误,它只是在没有初始警报的情况下触发操作。

echo $this->Form->postLink('<i class="icon-trash"></i> Delete',
    array('controller' => 'documents', 'action' => 'delete', $document['id']),
    array('escape' => false),
    null, __('Are you sure you want to delete # %s?', $document['file'])
);

有什么建议吗?

【问题讨论】:

    标签: php html cakephp cakephp-2.0


    【解决方案1】:

    参数数量错误

    通过添加escape =&gt; false 选项,您忘记删除第三个参数的占位符null。因此,您现在要传递 五个 参数。

    删除null,它应该可以工作;

    echo $this->Form->postLink(
        // title
        '<i class="icon-trash"></i> Delete',
    
        // URL
        array('controller' => 'documents', 'action' => 'delete', $document['id']),
    
        // Options
        array('escape' => false),
    
        // confirmMessage
        __('Are you sure you want to delete # %s?', $document['file'])
    );
    

    查看文档; FormHelper::postLink()

    【讨论】:

    • 文档实际上只列出了 3 个参数,让事情变得更加混乱。从 2.6 开始,“confirmMessage”参数是一个带有“confirm”键的选项,因此您可以编写:array('escape' =&gt; false, 'confirm' =&gt; __('Are you sure you want to delete # %s?', $document['file']))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多