Sevowen
(Sevowen)
May 10, 2014, 10:50am
1
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? =[
joblo
(Joe)
May 10, 2014, 1:59pm
2
And what’s the code of saveCounters()?
Sevowen
(Sevowen)
May 10, 2014, 2:13pm
3
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.
joblo
(Joe)
May 27, 2014, 8:04am
4
Thanks, didn’t know that this method exists …
redguy
(Maciej Lizewski)
May 27, 2014, 9:16am
5
Sevowen:
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? =[
try to change column to "NOT NULL DEFAULT 0". I think there might be issue with incrementing null value in column…
naveed1
(ndk)
June 5, 2014, 5:40pm
6
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 ?