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