在我的控制器中,我有 add($id = null) 函数。如果 iput add/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);
}
}
添加.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)); ?>