1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: zjw |
5
|
|
|
* Date: 2017/8/18 |
6
|
|
|
* Time: 下午12:54 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace zacksleo\yii2\backend\tests\models; |
10
|
|
|
|
11
|
|
|
use yii\base\InvalidParamException; |
12
|
|
|
use yii\helpers\ArrayHelper; |
13
|
|
|
|
14
|
|
|
class User extends \mdm\admin\models\User |
15
|
|
|
{ |
16
|
|
|
const STATUS_ACTIVE = 10; |
17
|
|
|
const STATUS_INACTIVE = 0; |
18
|
|
|
|
19
|
|
|
public function rules() |
20
|
|
|
{ |
21
|
|
|
return |
22
|
|
|
[ |
23
|
|
|
[['username', 'email', 'password_hash'], 'required', 'on' => 'reset'], |
24
|
|
|
['username', 'match', 'pattern' => '/^[a-z]\w*$/i', 'on' => 'reset'], |
25
|
|
|
['password_hash', 'match', 'pattern' => '/\d/', 'message' => '密码至少包含一位数字'], |
26
|
|
|
['password_hash', 'match', 'pattern' => '/[a-zA-Z]/', 'message' => '密码至少包含一个字母'], |
27
|
|
|
|
28
|
|
|
['username', 'filter', 'filter' => 'trim'], |
29
|
|
|
['username', 'unique'], |
30
|
|
|
['username', 'string', 'min' => 2, 'max' => 255], |
31
|
|
|
|
32
|
|
|
['email', 'filter', 'filter' => 'trim'], |
33
|
|
|
['email', 'email'], |
34
|
|
|
['email', 'unique'], |
35
|
|
|
|
36
|
|
|
['status', 'default', 'value' => self::STATUS_ACTIVE], |
37
|
|
|
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE]], |
38
|
|
|
|
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function beforeSave($insert) |
43
|
|
|
{ |
44
|
|
|
if (!$this->validate()) { |
45
|
|
|
throw new InvalidParamException($this->getErrors()); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
return parent::beforeSave($insert); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.