2009-12-21 69 views
2

我在这个控制器我在至极的功能控制器名为sales_controller我想:CakePHP的 - 更新上记录的用户信息

  1. 关于出售更新信息 - >完成
  2. 创建一个新的在其他模型记录 - >完成
  3. 更新的用户记录的字段 - >问题

我最后的尝试做到这一点是:

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)); 
} 

我知道)的方法$这个 - > Auth->用户(返回一个数组,我读了“保存”的阵列不工作...

我试图调用read功能上用户,但我仍然不知道该怎么做。

这一定是简单的事情,但我仍然是一个新手大声笑。

那么,任何人都可以帮助我吗?

谢谢

回答

2

试试这个:

App::import('Model', 'User'); 
$user = new User(); 
$user->id = $this->Auth->user('id'); 

/* if you really need to store the entire array, instead of accessing individual fields as needed */ 
$user_info = $this->Auth->user(); 

/* in saveField, add 'true' as a third argument to force validation, i.e. $user->saveField('nr', $this->Auth->user('nr') - 1, true) */ 
if ($user->saveField('nr', $this->Auth->user('nr') - 1)) { 
    $this->Session->setFlash(__('DONE! ', true)); 
    this->redirect(array('action' => $page, $params)); 
} 
+0

这就是谢谢;) – Canastro 2009-12-21 22:44:08

+0

你应该使用'$ user = ClassRegistry :: init('User');'来代替。 – deizel 2009-12-24 13:04:44

0

你已经加载了用户对象,但你没有做任何事情。您已将$ user的值设置为从Auth对象返回的数组,然后您正试图对其调用save方法。你想调用保存在用户对象上。

我想你想说的是:

$this->User->id = $this->Auth->user('id'); 
$this->User->save(array('nr'=>$nr)); 
+0

我做这些修改,但不是$这个 - > Auth->用户( '身份证' )我用$ this-> Auth-> user(),因为我需要加载关于用户的所有信息。但是我仍然收到空白页面并且没有修改用户。 print_r的输出($ this-> User);是:Array([User] => Array([id] => d12b1341-ee3e-11de-90ad-368a14c18e81 [login] => NoOne [email_address] => [email protected] [group_id] => 4b2f7282-cc98- 4db0-8994-0cd49279ab65 [nr] => 2 [active] => 1 [created] => 2009-12-20 01:18:55 [modified] => 2009-12-21 13:09:13)) – Canastro 2009-12-21 19:24:33