我正在尝试更新 profiles
表中的一行,以将用户个人资料图片重置为默认值 user.png
。我的 Controller 中有以下操作:
public function deleteProfilePicture() {
$this->layout = 'ajax';
// First find the profile ID from the user ID
$profileId = $this->Profile->find('first', array(
'condition' => array('User.id' => $this->Auth->user('id')),
'fields' => array('Profile.id'),
'recursive' => -1
));
$this->Profile->id = $profileId['Profile']['id'];
$this->Profile->saveField('picture', 'user.png', false);
}
但是,当我请求 URL (/profile/deleteProfilePicture
) 时,我没有收到任何错误,但数据库行未更新。我已通过使用 debug($profileId)
确保使用当前的配置文件 ID。
这里可能出了什么问题?
编辑:saveField()
的返回值:
array(
'Profile' => array(
'id' => '36',
'modified' => '2013-04-05 14:16:57'
)
)
最佳答案
尝试
$this->个人资料->id = $profileId['个人资料']['id'];
$this->个人资料->设置(数组(
'图片' => '用户.png'
));
$this->Post->save();
关于php - 设置单个数据库行的字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15833588/