使用CakePhp中的条件更新表中的所有字段

时间:2013-07-26 11:40:04

标签: sql-update cakephp-1.3 update-all

我有一个包含某些字段的表我想更新特定行中的所有列,我们该怎么做?

我想将这个数据数组更新到表

                 $travel_details=array(
                'userprofile_id'=>$upid,
                'day'=>$data['day'],
                'dayNumeric'=>$daynum,
                'morning_route'=>$morning_route,
                'morning_time'=>$morning_time,
                'evening_route'=>$evening_route,
                'evening_time'=>$evening_time,
                'traveller' =>$traveller
            );

我使用一个带有某些条件的代码

          $this->Singleroute->updateAll($travel_details,array('Singleroute.userprofile_id'=>$upid,'Singleroute.daynumeric'=>$daynum,
            'Singleroute.day'=>$data['day']));

但是这段代码不起作用..有没有办法更新al; l连续的字段? this is the table structure

1 个答案:

答案 0 :(得分:4)

$ travel_details应该是这样的

$travel_details['Singleroute']=array(
                'userprofile_id'=>$upid,
                'day'=>$data['day'],
                'dayNumeric'=>$daynum,
                'morning_route'=>$morning_route,
                'morning_time'=>$morning_time,
                'evening_route'=>$evening_route,
                'evening_time'=>$evening_time,
                'traveller' =>$traveller
            );

您需要在fields数组中指定模型。 否则运行您的查询

$this->Singleroute->updateAll($travel_details,array('Singleroute.userprofile_id'=>$upid,'Singleroute.daynumeric'=>$daynum,
            'Singleroute.day'=>$data['day']));

在此处阅读更多有关保存数据的信息 http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html#saving-your-data