CakePHP 3.0确认在烘焙模板中删除模式

时间:2015-10-28 15:58:26

标签: php twitter-bootstrap cakephp-3.0

我正在尝试制作一个集成了twitter bootstrap的烘焙主题。并使用bootstrap模式对话框确认删除数据。

我正在关注此链接here并使用CakePHP 3 Bootstrap Helpers

我正在plugins/themename/src/Template/Bake/Template/index.ctp& view.ctp

以下是index.ctp

中删除按钮的代码
<?= $this->html->link(__($this->Html->faIcon('close').' Delete'),
['action' => '#'],
['escape' => false,
'class' => 'btn btn-sm btn-danger btn-confirm',
'data-toggle'=> 'modal',
'data-target' => '#ConfirmDelete',
'data-action'=> Router::url(['delete', <%= $pk %>]),
false]) ?>

获取错误:

  

错误:未找到“路由器”类

查看/书签索引页面时

我在Cake\Routing\Router;

的顶部使用了index.ctp

然后我的view.ctp

<?= $this->Html->link(__($this->Html->faIcon('close')),
['action' => '#'],
['escape' => false,
'class' => 'btn btn-sm btn-danger btn-confirm',
'data-toggle'=> 'modal',
'data-target' => '#ConfirmDelete',
'data-action'=> ['/<%= $details['controller'] %>/delete/'.<%= $otherPk %>],
false]) %>

这似乎有效,但最终的数据操作是/Tags/delete/1,并且在T上有资金 - 不确定我是否会遇到问题?

index.ctp

中的Router :: url外,其他所有工作都有效

plugins/themename/src/Template/Layout.default.ctp

中的模态代码
<?php
$content = 'Are you sure you want to delete this element?';
echo $this->Modal->create(['id' => 'ConfirmDelete']) ;
echo $this->Modal->header('Confirm Delete', ['close' => false]) ;
echo $this->Modal->body($content, ['class' => 'my-body-class']) ;
echo $this->Modal->footer([
    $this->Form->button('Close', ['data-dismiss' => 'modal']),
    $this->Form->postLink(__('Delete'), ['action' => 'delete'],         
['class' => 'btn btn-danger'], false)]) ;
echo $this->Modal->end() ;
?>

用于更改模态

中的postLink操作的jQuery代码
jQuery.noConflict();

(function($) {
    $(document).ready(function () {
        $(".btn-confirm").on("click", function () {
            var action = $(this).attr('data-action');
            $("#ConfirmDelete form").attr('action', action);
        });
    })
})(jQuery);

1 个答案:

答案 0 :(得分:0)

这似乎有效,除非这不是真正的“CakePHP方式”。

index.ctp

Router::url(

替换$this->request->here
<?= $this->html->link(__($this->Html->faIcon('close')),
['action' => '#'],
['escape' => false,
'class' => 'btn btn-danger btn-confirm',
'data-toggle'=> 'modal',
'data-target' => '#ConfirmDelete',
'data-action'=> $this->request->here.'/delete/'.<%= $pk %>,
 false]) ?>

view.ctp

<%= $details['controller'] %>

中包装strtolower()
<?= $this->Html->link(__($this->Html->faIcon('close')),
['action' => '#'],
['escape' => false,
'class' => 'btn btn-danger btn-confirm',
'data-toggle'=> 'modal',
'data-target' => '#ConfirmDelete',
'data-action'=> '/'.strtolower('<%= $details['controller'] %>').'/delete/'.<%= $otherPk %>,
false]) %>

来自更高级的Cake用户的任何输入?

相关问题