Yii::app()->User In Afteraction Causes Error: "cannot Modify Header Information - Headers Already Sent"

In an afterAction method I check a user’s last activity and update it to DB and session if necessary. So in the afterAction method I have to use Yii::app()->user object.

The problem is if in any action I don’t call Yii::app()->user then the error “Cannot modify header information - headers already sent by” may appear. If I do (call Yii::app()->user in an action) then all works.

Another observation - if an output of an action is pretty small - then all may work fine without calling Yii::app()->user in the action.

How can I fix the problem?

Thank you