在我的控制器中,我添加了($ id = null)函數。如果iput添加/ 43它的作品。但是,如果任何驗證失敗它不加/ 43重新加載。 (在顯示錯誤信息之後)。 怎麼辦..版本1.3 控制器:添加函數時出錯
function add($id = null) {
if (!empty($this->data)) {
$this->ConsultingDet->create();
if ($this->ConsultingDet->save($this->data)) {
$this->Session->setFlash('The consulting det has been saved', true);
$this->redirect(array('controller' => 'patients', 'action' => 'home'));
} else {
$this->Session->setFlash('The consulting det could not be saved. Please, try again.', true);
}
}
if (is_null($id)) {
$this->set('id', 0);
}
}
add.ctp:
<div class="consultingDets form">
<?php echo $this->Form->create('ConsultingDet');?>
<fieldset>
<div class="sub1">
<?php
echo $this->Form->input('patient_id', array('type' => 'hidden', 'value' => $patient['Patient']['id']));
if ($id>0) //This (id) brings out error on redirection
echo $this->Form->input('id',array('type' => 'hidden', 'value' => $id));
echo $this->Form->input('temperature');
?>
</div>
</fieldset>
<?php echo $this->Form->end(__('Submit', true)); ?>
因爲你會渲染視圖添加?如果驗證是錯誤的,您可以重定向到引用者。 – Bob
也許是因爲你沒有設置id(順便說一句,它非常罕見,試圖添加一個沒有被驗證過的對象) – Yises