2012-04-16 24 views
2

したがって、追加操作では検証エラーが表示されますが、編集操作では表示されません。ここに私のコントローラからの抜粋は以下のとおりです。CakePHP:検証エラーが表示されないのはなぜですか?

期待通りここで私は、検証エラーメッセージを取得:

public function add() { 
     if ($this->request->is('post')) { 
      if ($this->User->save($this->request->data)) { 
       $this->Session->setFlash(__('The user has been saved.')); 
       $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The user could not be saved. Please try again.')); 
      } 
     } 
     $this->set('clients', $this->User->Client->find('list')); 
    } 

しかし、ここにいない:

public function edit($id = null) { 
     $this->User->id = $id; 
     if (!$this->User->exists()) { 
      throw new NotFoundException(__('Invalid user')); 
     } 
     if ($this->request->is('post') || $this->request->is('put')) { 
      if ($this->User->save($this->request->data)) { 
       $this->Session->setFlash(__('The user has been saved.')); 
       $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The user could not be saved. Please, try again.')); 
      } 
     } else { 
      $this->request->data = $this->User->read(null, $id); 
      unset($this->request->data['User']['password']); 
     } 
     $this->set('user', $this->User->read()); 
     $this->set('clients', $this->User->Client->find('list')); 
    } 
+0

誤植この行にそれを発見します。if(の$ this - > USER->の$ this - >(保存要求 - >データ/)) - 余分な/終了 – RichardAtHome

+0

ああで、私の元のコードには、私がSOで削除したコメントがありました。 –

答えて

0

はsetFlashです(「ユーザーが保存できませんでした」 )メッセージ発射?

デバッグの出力に含まは何(の$ this - > USER->によりvalidationErrors) - メッセージ失敗setFlash後にそれを追加

あなたのポストの配列は、それが保存するために必要なすべてのフィールドが含まれていますか?ポスト配列にない$ validateに必須フィールドがありますか? (Cakeはエラーを登録しますが、フォームにフィールドがない限り表示することはできません)。または、失敗したがフォームにフィールドを表示していない別の検証ルール?

関連する問題