CakePHP 1.3 控制器 save() 不保存数据

发布于 2024-09-02 06:37:27 字数 484 浏览 4 评论 0原文

我想向数据库添加一个新用户,并通过让他们填写表格并提交来实现。一切似乎都运行良好。在控制器中调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〆一缕阳光ご 2024-09-09 06:37:27

当您使用 FormHelper 创建表单时,它将生成如下输入名称:

<input type='text' name='data[Registratie][first_name]'>

提交表单后,cake 会将其推送到索引为“Registratie”的 $this->data 数组中

您可能需要将索引传递给模型保存时,

if ($this->Registratie->save( $this->data['Registratie'] ) ) {

我还会执行 var_dump($this->data)print_r($this->data) 以确保您的表单字段能够通过。

When you create a form using the FormHelper it will generate input names like:

<input type='text' name='data[Registratie][first_name]'>

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

if ($this->Registratie->save( $this->data['Registratie'] ) ) {

I would also do a var_dump($this->data) or print_r($this->data) to make sure your form fields are coming through.

如果没有你 2024-09-09 06:37:27

我也遇到了同样的问题,按照 Jack B Nimble 的指示修复了。使用 CakePHP 1.3

示例:

模型:联系人

$this->data['contact']

I had the same problem, fixed doing exactly what Jack B Nimble told. Using CakePHP 1.3

Sample:

Model: Contacts

$this->data['contact']
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文