2013-04-04 76 views
1

我試圖使用CakePHP計算後的意見,但使用此代碼CakePHP的:將數據保存在一列

  $this->autoRender=false; 
     $unformattedData = $this->GeneralNews->findById($id); 
     $data = $unformattedData['GeneralNews']; 
     $total = $data['views']; 
     $total = $total+1; 
     $this->GeneralNews->views =$total; 
     print_r($this->GeneralNews->views); 
     $this->GeneralNews->save($this->request->data); 

的print_r的告訴我這是已經在桌子上的意見,節省不happinging添加到他們+1 ..但它從來沒有保存在數據庫中..有什麼問題?

回答

4

試試這個代碼:

$unformattedData = $this->GeneralNews->findById($id); 
    $unformattedData['GeneralNews']['views'] = $unformattedData['GeneralNews']['views'] + 1; 
    $this->GeneralNews->save($unformattedData); 
1

也許更容易:

$this->GeneralNews->id = $id; 
$views = $this->GeneralNews->field('views'); 
$this->GeneralNews->saveField('views', $views + 1); 

希望這有助於。