Savecounters() Not Working

Hello, so I implemented saveCounters() code as follows:




$chapter = $this->loadModel($id);

$chapter->saveCounters(array('views'=>1));

$this->render('view',array(

    'model'=>$chapter,

));



And views column after I visit /chapters/views/id does not update! in db table my views is INT(11) type and is allowed to be NULL I am not sure why this is not working, any ideas? =[

And what’s the code of saveCounters()?

saveCounters() is yii method: http://www.yiiframework.com/doc/api/1.1/CActiveRecord#saveCounters-detail

Ok so I figured out why the problem occurs, the initial value was set to NULL and obviously you cant increment NULL value. Therefore initial value has to be set to int, in this case to 0.

Thanks, didn’t know that this method exists …

try to change column to "NOT NULL DEFAULT 0". I think there might be issue with incrementing null value in column…

It is working for me, but the view value in the table is increased by 2 not by 1.

So how to solve this problem ?