1

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 は、テーブルに既に追加されているビューを表示します..しかし、DBには保存されません..何が問題なのですか?

4

2 に答える 2

1

おそらくもっと簡単です:

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

お役に立てれば。

于 2013-04-04T08:38:52.003 に答える