Post View Counter


I search in yii portal, but i can’t find how to make a script to count view with MySql every time to view post add +1 to views and then reach count etc. 41.82 it should to be display 41.82K for shorter number :)

Sorry but im new in in yii and i try to learn about this :)

So if any can help, wrote here ;)

[color="#006400"]/* moved from Tips, Snippets and Tutorials */[/color]


In Controller something like this.

public function actionView($id)



        if (($count=Yii::app()->getGlobalState($model->title))==null)


        else Yii::app()->setGlobalState($model->title,++$count);



In view something like this.

div style="float:right;color:green;">

<?php echo Yii::app()->getGlobalState($model->title).' view(s)';?>


I hope I helped a bit.

If I understood you correctly than you can check out this extension.