Cakephp - 更新已登录用户的信息
我有一个名为 sales_controller 的控制器,在这个控制器上我有一个函数,我想:
- 更新有关销售的信息 ->完成
- 在其他模型上创建新记录 ->完成
- 更新用户记录上的字段 ->问题
我最后一次尝试这样做是:
App::import('model','User');
$user= $this->Auth->user();
$nr = $this->Auth->user('nr') - 1 ;
if($user->save(array('nr'=>$nr)))
{
$this->Session->setFlash(__('DONE! ', true));
this->redirect(array('action'=>$page,$params));
}
我知道方法 $this->Auth->user() 返回一个数组,并且我读到“保存”对数组不起作用...
我试图调用 read对用户起作用,但我仍然不知道应该怎么做。
这一定是很简单的事情,但我还是个新手哈哈。
那么,有人可以帮助我吗?
谢谢
I have a controller named sales_controller at this controller I got a function in wich I want to:
- update information about the sale -> DONE
- create a new record on other model -> DONE
- update a field on a user record -> PROBLEM
My last attempted to do this was:
App::import('model','User');
$user= $this->Auth->user();
$nr = $this->Auth->user('nr') - 1 ;
if($user->save(array('nr'=>$nr)))
{
$this->Session->setFlash(__('DONE! ', true));
this->redirect(array('action'=>$page,$params));
}
I know that the method $this->Auth->user() returns an array and I read that "save" does not work for arrays...
I was trying to call read function on users, but I still don't know how I should do it.
This must be something simple to do, but I'm still a newbie lol.
So, can anyone help me?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
您已经加载了 User 对象,但没有对它执行任何操作。您已将 $user 的值设置为从 Auth 对象返回的数组,然后尝试对其调用 save 方法。您想要对 User 对象调用 save。
我想你想说的是:
You've loaded the User object but you're not doing anything with it. You've set the value of $user to an array returned from the Auth object, and then you're trying to call the save method on it. You want to call save on the User object.
I think what you're trying to say is: