Cactiverecordbehaviour->Beforesave(): How To Use?

My behavior:



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)





        if($this->isNewRecord) {

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




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


        return true;



My Model:


	public function behaviors()


		return array(






  • 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…