更新查询不能在蛋糕PHP工作

时间:2012-04-09 08:03:30

标签: php cakephp cakephp-1.3

数据将以此形式出现

Array
(
[User] => Array
    (
        [first_name] => sxsaxs
        [last_name] => sdsdsd
        [contact_no] => 9569908024
        [address_1] => sdasd
        [address_2] => dsdsdsd
        [country_id] => 1
        [state_id] => 1
        [city_id] => 1
    )

)

users_controller.php中

public function my_account_edit(){

 if(!empty($this->data))
    {
         $this->User->id = $this->Auth->user('id');

     //   echo  $id= $this->User->id = $this->Auth->user('id'); it's working echo id

        if($this->User->save($this->data['User']))
            {

               $this->Session->setFlash("Account has been saved");
               $this->redirect(array('action' => 'my_account'));

            }


    }

但更新查询无效,其中id = $ this-> Auth-> user('id');

我的代码中没有问题

1 个答案:

答案 0 :(得分:1)

试试这个,

$this->data['User']['id'] = $this->Auth->user('id');

而不是

$this->User->id = $this->Auth->user('id');

同时检查此

$this->User->save($this->data['User'])将其设为$this->User->save($this->data)