0

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

我想将此数据数组更新到表中

                 $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']));

但是这段代码不起作用..有什么办法可以更新所有的;l 连续的字段? 这是表结构

4

1 回答 1

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

您需要在字段数组中指定模型。现在运行您的查询

$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

于 2013-07-29T13:00:25.690 回答