如何重定向到同一页面

时间:2012-05-18 06:58:42

标签: cakephp

在我的患者视图页面中,我使用ajax替换了'医生/添加'的div。现在我可以在患者视图页面中添加医生。但如果发生任何验证错误,它将直接从我的患者视图页面进行。到“医生/添加”页面显示验证信息 我希望它保留在当前页面上,在“添加”的输入字段中相应地显示验证消息。

function add() {
    if (!empty($this->data)) {
        $this->Doctors->create();
        if ($this->Doctors->save($this->data)) {
            $this->Session->setFlash(__('The Doctor has been saved', true));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The Doctor could not be saved. Please, try again.', true));
        }
    }

}

这是由于$ this->会话 - > setFlash in add()? 感谢...!

2 个答案:

答案 0 :(得分:4)

试试这个

$this->redirect($this->here);

答案 1 :(得分:0)

你能试试吗?

function add() {
if (!empty($this->data)) {
    $this->Doctors->create();
    if ($this->Doctors->save($this->data)) {
        $this->Session->setFlash(__('The Doctor has been saved', true));
        $this->redirect(array('action' => 'index'));
    } else {
        $this->Session->setFlash(__('The Doctor could not be saved. Please, try again.', true));


        $this->redirect(array('controller'=>'patient_controller_name', 'action' => 'view'));
    }
}

}