【发布时间】:2013-11-29 11:56:46
【问题描述】:
在使用带有 Cakephp 2.4.2 表单的 Twitter Bootstrap 模式时需要帮助吗?
我在视图中尝试了以下操作:
<div class="modal" id="myModal" tabindex="-1" role="dialog" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="modal-title" id="myModalLabel"><?php echo __('Form title'); ?></h3>
</div>
<div class="modal-body">
<?php
echo $this->Form->create('Person');
echo $this->Form->input('First name');
echo $this->Form->input('Last name');
echo $this->Form->end('Save');
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<script>
$(function(){
$('#myModal').modal('show');
});
</script>
表单会在加载时自动显示,这很好。
我在关闭表单/模式时遇到问题。 当用户单击保存时,模式保持打开状态,但根据需要将控制权传递给 PeopleController 中的操作。 当用户使用 Cancel 关闭 modal 时,modal 关闭,但 PeopleController 中的操作根本没有被调用。
我需要将控制权传递给 PeopleController 并关闭模式。
最好的方法是什么?
如何在模态页脚中单击按钮时将表单数据发布到控制器?
【问题讨论】:
-
你应该总是提到你正在使用的确切的 cakephp 版本。从您的代码来看,它看起来像 1.2。即使在 1.3 中,您也已经使用
$this->Form。 -
你是对的。我使用 cakephp 2.4.2,但忘记在代码中包含 $form=$this->Form 行。这里我只写了与问题相关的一段代码。
-
不,你没有将它映射到 $form,你只是总是使用 $this->Form。对于 CakePHP 中的 Twitter Bootstrap,请参阅 slywalker.github.io/cakephp-plugin-boost_cake
-
在 Boost 上没有任何关于模态的...
标签: jquery cakephp twitter-bootstrap