数据没有存储在数据库中cakephp
数据没有存储在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!");
}
}
}
保存失败,主要是因为验证错误。
这一行之前:
$this->Flash->set("The Topic has not been created!");
加入
pr($this->Reg->validationErrors)
,看看结果是
输出它显示为空数组 –
试试这个'$ result = $ this-> Reg-> save($ this-> request-> data);公关($结果)' –
创建()什么:如果$ data参数是通过,它将与数据库字段的默认值和模型实例将准备好用该数据保存(可在$ this-> data处访问)。
请阅读:http://book.cakephp.org/2.0/en/models/saving-your-data.html
做这样的事情:
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.'));
}
如果由于某种原因,你的数据不会保存,一定要检查,看看是否有些验证规则正在被打破。你可以通过输出来调试这种情况
if ($this->Recipe->save($this->request->data)) {
// handle the success.
}
debug($this->Recipe->validationErrors);
谢谢你!我得到了答案。是什么意思 '__' ?? –
你能打印$ this-> Reg-> validationErrors;在其他部分? –