2012-05-18 40 views
2

在我的患者視圖頁面中,我使用ajax替換了'doctors/add'的div。現在我可以在患者視圖頁面添加一名醫生。但是,如果發生任何驗證錯誤,它將直接從我的患者視圖頁面進行。到'醫生/添加'頁面顯示驗證消息。
我希望它留在當前頁面上,在'add'的輸入字段上適當地顯示驗證消息。如何重定向到同一頁

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-> Session-> setFlash在add()中嗎? 謝謝...!

+0

告訴我你的代碼..或模型驗證.. –

+0

你能解決這個問題?有哪些答案有幫助? 我面臨同樣的問題,我想知道什麼對你有用。謝謝! – fabricio

回答

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')); 
    } 
} 

} 
+0

$ this-> redirect(array('action'=>'view'));這也不成功。 – alexkd

+0

試試這個.......... – Pritom

3

試試這個

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