cakephp
2011-09-08 86 views 0 likes 
0

我需要使用updateall更新部件的位置和列
在CakePHP updateAll需要帮助

if (!empty($column3[0])) { 
      $column = preg_split("/,/", $column3[0]); 
      $name = $column[2]; 
      switch ($name) { 
     case 'My Profile': 
        $table = 'WidgetProfile'; 
       break; 
       case 'My script': 
        $table = 'WidgetScript'; 
        break; 
       case 'My Setting': 
        $table = 'WidgetSetting'; 
        break; 
       case 'Upload Script': 
        $table = 'WidgetUpload'; 
        break; 
       case 'My message': 
        $table = 'WidgetMessages'; 
        break; 
       default : 
        echo "Error3 0"; 
      } 
      $this->loadModel($table); 
      $row = $this->$table->find('count',array('conditions'=>array('user_id'=>'$id)); 
      if($row==0){ 
      $this->$table->set(array('column',=> 3, 'position' => 1,'user_id'=>$id)); 
      $this->$table->save(); 
      }else{ 
      $this->$table->updateAll(**?????????????**); 

     } 

如何使用updateAll它

回答

1

这不是很从这个问题清楚你想要什么要做,但它看起来像是在尝试更新现有记录,或者如果没有记录,请创建一个记录。两者都可以使用Model::save()。如果模型的ID被设置,它会更新,否则它会插入一个新的行。

$row = $this->$table->find(
    'first', 
    array(
     'conditions' => array('user_id'=> $id), 
     'fields' => "$table.id", 
     'recursive' => -1 
    ) 
); 

if(!empty($row)) { 
    $this->$table->id = $row[ $table ][ 'id' ]; 
} 

$this->$table->save(array('column' => 3, 'position' => 1, 'user_id'=> $id)); 
+0

如果(空($行)!){$ 这 - > $表 - > ID = $行[$表] [ 'ID']; } 用于 – taqman

+0

对不起,但我不明白你的意见。 – JJJ

+0

if(!empty($ row)){$ this - > $ table-> id = $ row [$ table] ['id']; } 请解释 – taqman

相关问题