我正在学习 Cakephp 概念,下面是我在 cakephp 中的控制器的代码,保存成功但取消将空行添加到数据库。
<?php
echo $this->Form->create('Customer');
echo $this->Form->input('customer_name');
.....
echo $this->Form->button(
'Save',
array('class' => 'button save')
);
echo $this->Form->button(
'Cancel',
array('class' => 'button cancel')
);
echo $this->Form->end();
?>
下面是我的视图形式
<?php
public function add() {
if ($this->request->is('post')) {
$this->Customer->create();
if ($this->Customer->save($this->request->data)) {
$this->Session->setFlash(__('Your customer has been saved.'));
return $this->redirect(array('action' => 'index'));
}
elseif ($this->Customer->cancel('')) {
$this->Session->setFlash(__('Customer info has not been saved'));
return $this->redirect(array('action' => 'index'));
}
}
}
?>