我有一個簡單的應用程序,顯示記錄列表,我想實現一個引導模態窗口來編輯記錄。我是新來的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>
這可能是實現,所以我願意接受建議走錯了路。任何幫助表示讚賞。
謝謝