signupform下的targetClass是什么 意思。

新手提问 · jasonyii · 于 3年前 发布 · 2002 次阅读

高级版的 frontend/models/signupform里有段代码

public function rules()

{
    return [
        ['username', 'filter', 'filter' => 'trim'],
        ['username', 'required'],
        ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
        ['username', 'string', 'min' => 2, 'max' => 255],

        ['email', 'filter', 'filter' => 'trim'],
        ['email', 'required'],
        ['email', 'email'],
        ['email', 'string', 'max' => 255],
        ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],

        ['password', 'required'],
        ['password', 'string', 'min' => 6],
    ];
}
----------

 ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
 ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
 
 这上面两行有  'targetClass' => '\common\models\User',  --这句话是什么 意思?
 我在user这个文件里,找不到相关的内容。
 
 
 

共收到 2 条回复
light#13年前 0 个赞

he name of the ActiveRecord class that should be used to validate the uniqueness of the current attribute value. If not set, it will use the ActiveRecord class of the attribute being validated.

forecho#23年前 0 个赞

保证 email 在 User 是唯一的

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册