savefield() 创建新行或记录而不是更新特定记录
我使用 cakePHP 1.26。
我在一个表中得到了一些示例数据,该表有两个字段:{user_id,avatar}
我试图更新数据库中的旧记录:
$who=$this->Session->read('user.user_id'); // 12 was retrieved in this case
$c = "http://www.abc.com/myimage.gif";
$this->Test->User->user_id = $who;
$result = $this->Test->User->saveField('avatar',$c);
if( $result==true){return "ok";}
当我检查数据库时,我看到创建了一条新记录,但 user_id 12 的旧记录根本没有更新
请帮忙。
I am using cakePHP 1.26.
I got some sample data in a Table which has got two field: {user_id, avatar}
I was trying to update an old record in the database :
$who=$this->Session->read('user.user_id'); // 12 was retrieved in this case
$c = "http://www.abc.com/myimage.gif";
$this->Test->User->user_id = $who;
$result = $this->Test->User->saveField('avatar',$c);
if( $result==true){return "ok";}
When I checked the database, I saw a new record was creeated instead, but the old record with user_id 12 was not updated at all
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题就在这里:
假设您有正常的 CakePHP DB 约定,它应该是:
The problem is here:
Assuming that you have normal CakePHP DB convention it should be: