私の意見では、送信ボタンとキャンセルボタンがあるフォームがあります。両方のアクションが私をインデックスページに戻します。唯一の違いは、Submitは通常のdbサブミットを行い、「請求書が更新されました」というメッセージを表示するのに対して、Cancelは更新をキャンセルし、 'Update cancelled'を表示することです。ここでは、コントローラのコードは次のとおりです。CakePHPキャンセルボタンが起動しない
<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'));
?>
しかし、ボタンが押されていない問題は、それは常に最初のメッセージを返します。
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.');
}
}
}
そして、ここでは、ビューがあります。また、db submitも実行します。
NetbeansでXDebugを使用してみましたが、それは別の時間の話です。通常私の間違いは他人には明らかです。だから、誰かが私を軌道に乗せることを望んでいる。
これをelse文の直後に置き、[キャンセル]をクリックすると、出力はどのようになりますか? 'デバッグ($ this-> params); exit; ' – Wylie
リンクを使用してインデックスを作成しています –