2016-01-13 16:40:45 3281次浏览 1条回答 0 悬赏 10 金钱
namespace app\models;

use Yii;
use yii\base\Model;


class RegisterForm extends Model
{
    public $email;
    public $password;
	public $password_repeat;


    public function rules()
    {
        return [
            [['email', 'password', 'password_repeat'], 'required'],
			['email', 'email'],
			//['email', 'unique', 'targetClass' => '', 'message' => '邮箱名已存在。'],
			[['password', 'password_repeat'], 'string', 'length' => [6, 20]],
			['password', 'checkPassword'],
			['password_repeat','compare','compareAttribute' =>'password','message'=>'两次输入的密码不一致。'],
        ];
    }

    public function register()
    {
        //处理一些东西
		//注册相关的
        return false;
    }
	
	public function attributeLabels()
    {
        return [
            'email' => '邮箱',
            'password' => '密码',
			'password_repeat' => '重复密码',
        ];
    }
	
	public function checkPassword($attribute, $params)
	{
		if (!ctype_alnum($this->$attribute)) {
			$this->addError($attribute, '必须包含字母或数字。');
		}
	}
}

checkPassword 这个独立验证器 使用不了 我代码书写有问题吗 各位大哥们

  • 回答于 2016-01-14 09:15 举报

    这是我写的 验证recommender的 你自己看下吧

    public function chkmepay($attribute,$params){
    	if(!empty($this->recommender)){		
    		$success = Yii::$app->mp->checkMepay($this->recommender);	   
    		 if(!isset($success->email)){			     
    			 $this->addError('recommender',Yii::t('mbarter','Mepay没有此用户,请重新输入'));
    		 }
    	}
    }
    
您需要登录后才可以回答。登录 | 立即注册
thinfell
职场新人

thinfell

注册时间:2016-01-12
最后登录:2018-07-19
在线时长:5小时41分
  • 粉丝0
  • 金钱15
  • 威望0
  • 积分65

热门问题