【发布时间】:2015-03-04 23:27:58
【问题描述】:
我有一个显示记录列表的简单应用程序,我想实现一个引导模式窗口来编辑记录。我是 php 新手,但我正在尝试 cakePHP,因为我更喜欢 MVC。
我在每个表格行上都有一个下拉菜单,选择后,我想打开模式,进行更改并保存。目前,我正在实现一个链接来调用 url 以获取数据异步并使用响应更新 div。我有这个工作,但数据正在被缓存,因此即使在选择新记录后,它也会显示显示的第一条记录中的数据。我确信我可以找到一种方法来清除它,但这让我质疑我是如何实现模态窗口的。
列表视图有以下内容:
<li>
<?php
echo $this->Js->link("Edit settings","/units/edit/".$unit['Unit']['id'] ,
array('update' => '#editModal',
'htmlAttributes' => array(
'data-toggle' => 'modal',
'data-target' => '#editModal'
)));
?>
</li>
控制器:
if (!$this->Unit->exists($id)) {
throw new NotFoundException(__('Invalid unit'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->Unit->save($this->request->data)) {
$this->Session->setFlash(__('The unit has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The unit could not be saved. Please, try again.'));
}
} else {
if ($this->request->is('ajax')) {
$this->render('edit', 'ajax');
}
}
编辑视图:
<div class="modal-dialog">
× 模态标题
<?php
echo $this->Form->create('Unit');
echo $this->Form->input('name', array('class' => 'form-control', 'div' => 'form-group', 'disabled' => 'disabled'));
echo $this->Form->input('internet_class_id', array('class' => 'form-control', 'div' => 'form-group'));
$offOn = array(0 => 'Off', 1 => 'On');
echo $this->Form->input('water_setting_id', array('options' => $offOn, 'default' => 0,
'class' => 'form-control', 'div' => 'form-group'));
$amenitySettings = array(0 => 'Deny', 1 => 'Allow');
echo $this->Form->input('amenity_setting_id', array('options' => $amenitySettings, 'default' => 0,
'class' => 'form-control', 'div' => 'form-group'));
echo $this->Form->input('cable_setting_id', array('options' => $offOn, 'default' => 0,
'class' => 'form-control', 'div' => 'form-group'));
echo $this->Form->hidden('id');
echo $this->Form->hidden('building_id');
echo $this->Form->button('Save', array('type' => 'submit', 'class' => 'btn btn-primary'));
echo $this->Form->end();
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
这可能是错误的实施方式,因此我愿意接受建议。任何帮助表示赞赏。
谢谢
【问题讨论】:
标签: jquery twitter-bootstrap cakephp