我正在尝试制作一个集成了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
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);
答案 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用户的任何输入?