Component Vs Behavior

Hello,

I seem to have come to a standstill when it comes to what I am trying to achieve within yii. I am not sure the correct way to go about doing what i’d like to do. I know I can do this using a behavior, and I have, however I don’t believe this is the best approach and would like some input.

I am looking to log every pageload on my website basically, it is a small website where users will be able to purchase items, and I would like logs for the purposes of security, user tracking, page tracking, link tracking, and even down to tracking the time spent on certain pages, if they left from a certain page, etc.

I currently have a behavior in order to do this, I have in my main/config.php




'behaviors' => array(

        'onBeginRequest' => array(

            'class' => 'application.components.UserLogger'

        )

    ),



and then I have a UserLogger which extends CBehavior and runs like this




public function attach($owner)

    {

        $owner->attachEventHandler('onBeginRequest', array($this, 'startUserLogger'));

    }


    public function startUserLogger($event)

    {



Basically on every pageload it saves a user log and ideally i’d like to be able to have a public variable which will hold the ID (so that I can attach programlogs to pageloads) and stuff like that. Is there a better solution to do what I’m trying to do ?

Also, I am getting ready to jump into the world of user management with Yii, I have created login forms before using yii but I have never actually gone as far as creating roles/tasks/etc. My question is this:

does yii load the role every time a user logs in / revists the site & a cookie logs them in ? Or do I need to keep track of explicity what role each user is assigned so that if they need to change roles I can remove the old one?

Is it also possible to assign roles to guests ? I have a website which will feature a homepage in which a user has to agree they are over a certain age (21) and am trying to determine the best way to prevent them from going to another webpage without already clicking that they are 21. No, my website is not running anything sketchy nor relating to adult videos.