How to validate email and email already exist or not check, in Yii Framework?

后端 未结 6 995
日久生厌
日久生厌 2020-12-18 21:15

How to validate email using Yii Model validation rules function code. Also how to check email exist or not using Model validation rules function in Yii.

6条回答
  •  独厮守ぢ
    2020-12-18 21:39

    You can set your model validations as below

    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
                //First parameter is your field name of table which has email value
            array('email', 'email','message'=>"The email isn't correct"),
            array('email', 'unique','message'=>'Email already exists!'),            
        );
    }
    

    Yii Reference Link For More Detail: http://www.yiiframework.com/wiki/56/

提交回复
热议问题