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

后端 未结 6 1006
日久生厌
日久生厌 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:34

    For Yii2 I used the following in a model called Register which will use the User Class.

    public function rules()
    {
        return [
    
            ['Email', 'filter', 'filter' => 'trim'],
            ['Email', 'required'],
            ['Email', 'email'],
            ['Email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
    
        ];
    }
    

    You need to use targetClass and put the Namepsace for the Class User

提交回复
热议问题