Logout User In Component/cpntroller

Hello guys

I want to logout user everywhere in my site when my condition satisfy. The best way, is to put my code in base controller class which will execute first of all I think. My code is:




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

{

	$user = User::model()->findByAttributes(array(), 'id=:id AND username=:username', array(

		':id' => Yii::app()->user->id,

		':username' => Yii::app()->user->username,

	));

	if($user === NULL)

	{

		$this->redirect(Yii::app()->createUrl('site/logout'));

	}

}



But when it want to excute $this->redirect it can’t connect to logout action, what I can do?

Any help will be appreciated, thanx in advance

Instead of




$this->redirect(Yii::app()->createUrl('site/logout'));



I put this:




Yii::app()->user->logout;



simply add into your config main.php file -


'components'=>array(    

	'user'=>array(

	   // enable cookie-based authentication

	   'allowAutoLogin'=>true,

	   'autoRenewCookie' => true,

           'authTimeout' => 86400, //kills session after 24 hours just in case above fails or if a user clicks remember me it will only last for this duration.

           'loginUrl' => array('site/login'),

	),

 )