Joy灬小痴 2017-01-04 15:20:24 2592次浏览 2条回复 2 0 0

今天写了一个验证方法 记得与yii1.0有一些差别现在跟大家分享一下 我是遇到了跨库查询的问题 所以只能先去查询了 rule里边需要验证某个字段可以写方法单独验证下边是我写的方法 废话不多说直接代买贴上

public function rules() {

parent::rules();
return [
    ['family_mobile','Mobile','skipOnError'=>false],
];

}

public function Mobile($attribute, $params)

{
    $model = new  AnchorFamily();
    $mobileAll = $model->getUserMobile();
    $data = array();
    foreach ($mobileAll as $k=>$v)
    {
        $data[] = $v['apply_phone'];
    }
    $mobile = $this->$attribute;
    if (array_search($mobile,$data))
    {
        return $this->addError($attribute,"手机号已存在请重新填写");
    }
    return true;
}
您需要登录后才可以回复。登录 | 立即注册