CakePHP 1.3 控制器 save() 不保存数据
我想向数据库添加一个新用户,并通过让他们填写表格并提交来实现。一切似乎都运行良好。在控制器中调用 save()
之前,我返回所有数据,并且所有必要的数据都在那里。它是有效的,因为没有返回错误。
但随后什么也没有发生。我正在返回我的表单,没有显示任何错误。 这是我的“保存行”:
if($this->Registratie->save($this->data)) {
我没有使用任何 beforeSave()
方法。
使用 debug($this->validationErrors);
显示:
app/controllers/registratie_controller.php (line 45)
这是上面的代码行。
我已经一遍又一遍地检查我的代码。问题可能是什么?
I want to add a new user to the database, and do so by making them fill in a form and submitting this. All seems to work fine. Just before my save()
call in the controller I return all data and all necessary data is there. It is valid(ated), since no errors are returned.
But then nothing happens. I'm being returned to my form without any errors being shown.
This is my 'save-line':
if($this->Registratie->save($this->data)) {
I'm not making use of any beforeSave()
methods.
Using debug($this->validationErrors);
shows:
app/controllers/registratie_controller.php (line 45)
Which is the line of code from above.
I've been going through my code over and over. What could the problem be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用 FormHelper 创建表单时,它将生成如下输入名称:
提交表单后,cake 会将其推送到索引为“Registratie”的 $this->data 数组中
您可能需要将索引传递给模型保存时,
我还会执行 var_dump($this->data) 或 print_r($this->data) 以确保您的表单字段能够通过。
When you create a form using the FormHelper it will generate input names like:
Once the form is submitted cake will push that into the $this->data array with an index of 'Registratie'
You probably need to pass the index to the model when saving
I would also do a var_dump($this->data) or print_r($this->data) to make sure your form fields are coming through.
我也遇到了同样的问题,按照 Jack B Nimble 的指示修复了。使用 CakePHP 1.3
示例:
模型:联系人
I had the same problem, fixed doing exactly what Jack B Nimble told. Using CakePHP 1.3
Sample:
Model: Contacts