Yii How To Interrupt Data Insert And Logout Instantly From The System

What I want is that when a user submits a form (when clicked save), the system state should be checked and if it does not match, I need to interrupt data save and logout the user from the system. I tried this with beforeSave() and it works but the problem is that it does not work simultaneously.

i.e.- when the user click save button, data won’t insert and when user clicks save button again then the user logs out from the system.

This is my current code:

//protected/model/supplier.php

class Supplier extends CActiveRecord{

 protected function beforeSave(){


        if(Yii::app()->params->SYSTEM_STATE==3){


            return false;


            Yii::app()->session->destroy();


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


        }








        return parent::beforeSave();


    }

}

Check it in the controller action before the save method call and redirect to logout url.

Did mean redirect to logout url as Yii::app()->user->logout() ?

I tried, but still result is same.

No . use


 $this->redirect(array('site/logout')); // Your logout action path