0
在我看來,我有一個提交和取消按鈕的表單。這兩個操作都會將我返回到我的索引頁。唯一的區別是提交會執行正常的數據提交併顯示消息「您的發票已更新」,而取消應取消更新並顯示「更新取消」。這裏的控制器代碼:CakePHP取消按鈕不會觸發
public function edit($id = null) {
$this->Invoice->id = $id;
$this->set('invoice', $this->Invoice->read(null, $id));
//Check for $_GET
if ($this->request->is('get')) {
$this->request->data = $this->Invoice->read();
} else {
// Bail if cancel button pressed
if (isset($this->params['form']['cancel'])) {
$this->Session->setFlash('Update canceled.');
$this->redirect(array('action' => 'index'));
} else if ($this->Invoice->save($this->request->data)) {
$this->Session->setFlash('Your Invoice has been updated.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to update your Invoice.');
}
}
}
這裏是視圖:
<fieldset>
<legend>Enter New Values</legend>
<li><?php echo $this->Form->input('purchaseOrderNumber'); ?></li>
<li><?php echo $this->Form->input('siteAddress'); ?></li>
<li><?php echo $this->Form->input('siteCity'); ?></li>
<li><?php echo $this->Form->input('siteState'); ?></li>
<?php
echo $this->Form->button('Submit Form', array('type' => 'submit'));
echo $this->Form->submit('Cancel', array('div' => false, 'name' => 'cancel'));
?>
然而,無論哪個按鈕被按下時,它總是返回的第一個消息。它也執行數據庫提交。
我試着用Netbeans使用XDebug失敗,但這是一個不同時間的故事。通常我的錯誤對其他人來說很明顯。所以,我希望有人能讓我回到正軌。
如果你把它放在你的else語句後面並且點擊取消,那麼輸出是什麼? '調試($這個 - > PARAMS);退出;' – Wylie 2012-04-10 19:16:07
我剛剛使用鏈接返回索引結束 – 2012-04-12 17:10:41