2016-07-14 33 views
0

データがcakephpのデータベースに格納されていません。データがcakephpのデータベースに保存されていません

if ($this->request->is('post')) { 
     $this->Reg->create('User'); 
     // pr($this->Reg->save($this->request->data['user']['firstname'])); 
     if ($this->Reg->save($this->request->data)) { 

      $this->Flash->set("The Topic has been created!"); 
       $this->redirect(array('action' => 'Reg')); 
     } else { 
      $this->Flash->set("The Topic has not been created!"); 
     } 
    } 
} 
+0

$ this-> Reg-> validationErrorsを印刷してください。それ以外の部分? –

答えて

1

保存が主な原因の検証エラーのため、失敗しています。この行の前に

$this->Flash->set("The Topic has not been created!");

pr($this->Reg->validationErrors)

に追加して、結果が

+0

出力が空の配列として表示されています –

+0

この '$ result = $ this-> Reg-> save($ this-> request-> data); pr($ result) ' –

0

)は(を作成してあるものを参照してください:$ dataパラメータがある場合合格すると、データベースフィールドのデフォルトとマージされます。モデルインスタンスはそのデータ($ this-> dataでアクセス可能)で保存する準備が整います。

お読みください:あなたのデータが保存されていない何らかの理由で、いくつかの検証ルールが破られているかどうかを確かめてください

if ($this->request->is('post')) { 
     $this->Reg->create(); 
     if ($this->Reg->save($this->request->data)) { 
      $this->Flash->success(__('Your post has been saved.')); 
      return $this->redirect(array('action' => 'Reg')); 
     } 
     $this->Flash->error(__('Unable to add your post.')); 
    } 

http://book.cakephp.org/2.0/en/models/saving-your-data.html

はこのような何かを。この状況をデバッグするには、

if ($this->Recipe->save($this->request->data)) { 
    // handle the success. 
} 
debug($this->Recipe->validationErrors); 
+0

ありがとう!私は答えを得た。 「__」の意味は何ですか? –

関連する問題