Event And Behavior

I try atach behavior to component (via config) and set eventheandler to component event from this behavior, but it not working, and i don’t get any errors





--------Config---------


'post'=>array(

       'class'=>'post',

       'behaviors'=>array(

             'postbehavior'=>array(

              'class'=>'PostBehavior',

        ),

      ),

  ),


---------Component-----------


class Post extends CApplicationComponent{

    

    

    public function init(){

        

    }    

    

    public function onClicked($event){

        $this->raiseEvent('onClicked', $event);

    }

       

}


-------------behavior--------------


class PostBehavior extends CBehavior{

    

    public function events(){

        

        return array(

            'onClicked'=>'postHeandler',

        );

        

    }

    

    public function postHeandler($event){

        echo "i am behavor !";

    }

}




--------------Controller---------------


public function actionIndex(){

	    

        

        Yii::app()->post->onClicked($event);

        

		$this->render('index');

	}









Dear Friend

I am rewriting the code.

Kindly get note of modifications.




--------Config---------


'post'=>array(

       'class'=>'Post', //NOT 'post'

       'behaviors'=>array(

             'postbehavior'=>array(

              'class'=>'PostBehavior',

        ),

      ),

  ),


---------Component-----------


class Post extends CApplicationComponent{

    

    

   /* public function init(){  //NO NEED TO OVERIDE THE PARENT INIT METHOD.

        

    }   */ 

    

    public function onClicked($event){

        $this->raiseEvent('onClicked', $event);

    }

       

}


-------------behavior--------------


class PostBehavior extends CBehavior{

    

    public function events(){

        

        return array(

            'onClicked'=>'postHeandler',

        );

        

    }

    

    public function postHeandler($event){

        echo "i am behavor !";

    }

}




--------------Controller---------------


public function actionIndex(){

            

        

        Yii::app()->post->onClicked(new CEvent);//not $event as it is undefined.

        

                $this->render('index');

        }




Regards.