CakePHP2系でvalidateをリダイレクト先で表示
遷移元でvalidateの結果を表示する方法
if($this->'Model名'->save($this->request->data)) { // success // リダイレクト } else{ // fail // 遷移元でvalidate結果を表示 }
さて、CakePHPでは遷移元にどうやって?ってとこでググり始める
参考リンク
まさになサイト
すばらしい記事ありがとうございます。
cakeではリファラをこうやって使うのね。なるほどです。
$this->Session->write('errors.Comment',$this->'Model名'->validationErrors); $this->Session->setFlash(__('Failed to save.')); $this->redirect( $this->referer() );
validate結果を渡すcontrollerではbeforeFilterで受ける
public function beforeFilter(){ parent::beforeFilter(); if($this->Session->read('errors')){ foreach($this->Session->read('errors') as $model => $errors){ $this->loadModel($model); $this->$model->validationErrors = $errors; } $this->Session->delete('errors'); } }