Using Login (Useridentity) Error Code

Hello friends;

I have piece of code like below, and I want to find Login error code (eg:self::ERROR_USERNAME_INVALID) if any error exist, to show user a proper message through ajax.

$model=new LoginForm;

$model->username = $_POST['username'];

$model->password = $_POST['password'];

$model->rememberMe = ($_POST['remember'] == 'on') ? TRUE : FALSE;


if(isset($_POST['isAjax']))// Codes For Ajax Login (Modal Login)


    if($model->validate() && $model->login())


        $result = 'enter';


    else if(//here I want that code to know which error occurred when user tried to login)




Could you help me, how I can reach these error code in my site controller?

Thanks in advance

Why are you using mysql_real_escape_string? This should not appear anywhere in your Yii codebase.

Any time that you explicitly need to escape database content, you should be using parameterization.

Thank you Keith and I appreciate if you teach me how I can reach login error code either

Perhaps you could add an attribute to your LoginForm model and set it after validation:

class LoginForm extends CFormModel


    public $loginErrorCode;


    public function validate()


        // If validation fails, update $this->loginErrorCode here



Really I owe you Keith, I wrote a public function in LoginForm Model which return


thanks for sharing your knowledge