我有一个简单的应用程序,显示记录列表,我想实现一个引导模态窗口来编辑记录。我是新来的PHP,但我尝试cakePHP,因为我更喜欢MVC。cakephp实现模式编辑窗口
我在每个表格行上都有一个下拉列表,选择后,我想要打开模式,进行更改并保存。目前,我正在实现一个链接来调用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>
这可能是实现,所以我愿意接受建议走错了路。任何帮助表示赞赏。
谢谢