私の見解では、送信ボタンとキャンセル ボタンのあるフォームがあります。どちらのアクションでも、インデックス ページに戻ります。唯一の違いは、Submit は通常のデータベース送信を行い、「Your Invoice has been updated.」というメッセージを表示するのに対し、Cancel は更新をキャンセルし、「更新がキャンセルされました.」と表示することです。コントローラーのコードは次のとおりです。
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'));
?>
ただし、どのボタンが押されても、常に最初のメッセージが返されます。また、db submit も実行します。
Netbeans で XDebug を使用しようとして失敗しましたが、それはまた別の話です。通常、私の間違いは他の人には明らかです。だから、誰かが私を軌道に乗せてくれることを願っています。