Where is the best place for running a piece of code on every page view?

I’m trying to simply put this to be run on every page view:




if(!Yii::app()->user->isGuest)

  $user->last_visit = time();



Is there a best practice for running something like this with the least amount of overhead? Preferably somewhere that already has a “$user = new User;” model made so on every page view a new one isn’t made.

Would putting it in the models/User.php file, in the __construct() of the “class User extends CActiveRecord” class do the trick using “$this->last_visit = time();” conditionally if the user is not a guest? Would it be used on every pageview to track when the last view was or is there an even better method I’m not aware of?

Thanks,

slickplaid

I would put this in a widget (protected/component/) and don’t worry about the overhead.