|
|
@ -0,0 +1,55 @@ |
|
|
|
<?php |
|
|
|
namespace Wiggins\MyProject; |
|
|
|
|
|
|
|
require __DIR__."/../vendor/autoload.php"; |
|
|
|
require __DIR__.'/../vendor/yiisoft/yii2/Yii.php'; |
|
|
|
|
|
|
|
use yii\base\Model; |
|
|
|
|
|
|
|
//定义一个模型
|
|
|
|
class UserInput extends Model |
|
|
|
{ |
|
|
|
public $name; |
|
|
|
public $email; |
|
|
|
public $password; |
|
|
|
public $pwdConfirm; |
|
|
|
|
|
|
|
public function attributeLabels() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'name' => '3-20个英文或数字字符', |
|
|
|
'email' => '你的邮箱地址', |
|
|
|
'password' => '3-10个英文或数字字符', |
|
|
|
'pwdConfirm' => '需要与密码一致', |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function scenarios() |
|
|
|
{ |
|
|
|
return[ |
|
|
|
'login' => ['name','password'], |
|
|
|
'register' => ['name','email','password','pwdConfirm'], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function rules() |
|
|
|
{ |
|
|
|
return[ |
|
|
|
//用户名长度
|
|
|
|
['name','string','length'=>[3,20],'message'=>'用户名长度为3至20个字符'], |
|
|
|
//用户名唯一性
|
|
|
|
//['name','unique'],
|
|
|
|
//邮件格式
|
|
|
|
['email','email'], |
|
|
|
//密码格式
|
|
|
|
['password','string','length'=>[3,10]], |
|
|
|
//确认密码与密码需一直
|
|
|
|
['pwdConfirm','compare','compareAttribute'=>'password','message'=>'两次密码必须一致'], |
|
|
|
//注册场景
|
|
|
|
[['name','email','password','pwdConfirm'],'required','on'=>'register'], |
|
|
|
//登录场景
|
|
|
|
[['name','password'],'required','on'=>'login'], |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
?>
|