【发布时间】:2025-12-18 20:30:01
【问题描述】:
我在订阅数据库表中添加了两个新字段,即first_name 和last_name 到表subscriptions
但是每当我从表单返回值并尝试保存它们时,它就不会保存到数据库中?
我的代码如下
$this->data['Subscription']['id'] = $subscription['Subscription']['id']; //To get the primary key
$this->data['Subscription']['first_name']; //Echoes out the name I entered
$this->data['Subscription']['last_name']; //Echoes out the surname I entered
然后我打电话给$this->Subscription->save();,它保存了除了我新添加到表中的字段之外的所有其他字段,我尝试了 $this->Subscription->set($this->data['Subscription']);也没有什么想保存的?
我不确定我在这里做错了什么?任何帮助将不胜感激!!!!
【问题讨论】:
-
我看不到您将值分配给 first_name 和 last_name 的位置。您可以发布该代码吗?尝试在保存之前使用
debug($this->data);以查看该数组中的实际内容。 -
您可以发布输入数据的部分视图吗?您是否尝试过查看 this->data 是否确实有 first_name 和 last_name?
标签: cakephp