使用模态框进行删除确认,代替cakephp 2.x中的警报

时间:2014-04-12 06:13:48

标签: php cakephp cakephp-2.0 cakephp-2.1 cakephp-2.3

我烘焙了一个cakephp项目,我想使用nifty-modalbox进行删除确认代替普通警报。任何人都知道如何做到这一点。

以下是该方案: Bootstrap 3 jquery.niftymodals.js

这是所需的html代码。

<a class="btn btn-primary btn-mono2 btn-flat md-trigger" data-modal="dark-primary">Delete</a>
<!-- Nifty Modal -->
                <div class="md-modal md-dark md-effect-3" id="dark-primary">
                    <div class="md-content">
                      <div class="modal-header">
                        <h3>Custom Header Color</h3>
                        <button type="button" class="close md-close" data-dismiss="modal" aria-hidden="true">&times;</button>
                      </div>
                      <div class="modal-body">
                        <div class="text-center">
                          <h4><strong>Awesome!</strong></h4>
                          <h5>Can you say supercalifragilisticoexpialidoso?</h5>
                        </div>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-primary btn-mono2 btn-flat md-close" data-dismiss="modal">Cancel</button>
                        <button type="button" class="btn btn-primary btn-mono2 btn-flat md-close" data-dismiss="modal">Proceed</button>
                      </div>
                    </div>
                </div>

Cakephp代码:

<?php   echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $post['Post']['id']), null, __('Are you sure you want to delete # %s?', $post['Post']['id'])); ?>

有人可以建议吗?

1 个答案:

答案 0 :(得分:1)

如果你想使用cakePHP,你可以创建your own helper,并让它扩展FormHelper。然后你覆盖postLink method并根据需要定制它。您要查找的文件是Cake/View/Helper/FormHelper.php。这是确认对话框的当前cakePHP实现(从第1786行开始):

if ($confirmMessage) {
            $confirmMessage = str_replace(array("'", '"'), array("\'", '\"'), $confirmMessage);
            $options['onclick'] = "if (confirm('{$confirmMessage}')) { {$onClick} }";
}
祝你好运!