Cactiverecordbehaviour->Beforesave(): How To Use?

My behavior:

components\SaveUserIdBehavior.php




<?php

class SaveUserIdBehavior extends CActiveRecordBehavior

{


    protected function beforeSave($event)

    {

        Yii::trace ("beforeSave del behavior scatenato");

        $now = new DateTime();

        $now_string = $now->format("Y-m-d H:i:s");


        if(null !== Yii::app()->user)

           $id=Yii::app()->user->id;

        else

            $id=-1;

        

        if($this->isNewRecord) {

            $this->owner->create_time = $now_string;

            $this->owner->create_user_id=$id;

        }

        

        $this->owner->update_time = $now_string;

        $this->owner->update_user_id=$id;

        return true;

    }

}



My Model:

models/User.php





	public function behaviors()

	{

		return array(

			'SaveUserId'=>array(

	            'class'=>'SaveUserIdBehavior',

	        ),


		);

	}



  • User is being saved right, but specified attributes were not set.

  • Also, ‘trace’ is not … tracing … so the code is not executed

  • But if I introdue a php error into the file, execution stops, so the class is being used…

What am I missing?

I think this line from the class reference might be the answer:

Try changing the method visibility to public.

thanks, this resolved all issues…