-
Notifications
You must be signed in to change notification settings - Fork 211
/
IndexFrom.php
101 lines (90 loc) · 2.9 KB
/
IndexFrom.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace web\index\model;
use mix\base\Model;
/**
* Index 表单模型类
* 这是一个表单模型的范例,一个表单模型对应一个控制器,表单模型内调用数据模型操作数据库
* 一个数据模型对应一个数据表,数据表是公用的,所以数据模型应该在公共模块
* @author 刘健 <coder.liu@qq.com>
*/
class IndexFrom extends Model
{
public $a;
public $b;
public $c;
public $d;
public $e;
public $f;
public $g;
public $h;
public $i;
public $j;
public $k;
public $l;
public $m;
public $n;
public $r;
// 规则
public function rules()
{
return [
['a', 'integer', 'unsigned' => true, 'min' => 1, 'max' => 1000000, 'length' => 10, 'minLength' => 3, 'maxLength' => 5],
['b', 'double', 'unsigned' => true, 'min' => 1, 'max' => 1000000, 'length' => 10, 'minLength' => 3, 'maxLength' => 5],
['c', 'alpha', 'length' => 10, 'minLength' => 3, 'maxLength' => 5],
['d', 'alphaNumeric', 'length' => 10, 'minLength' => 3, 'maxLength' => 5],
['e', 'string', 'length' => 10, 'minLength' => 3, 'maxLength' => 5, 'filter' => ['trim', 'strip_tags', 'htmlspecialchars']],
['f', 'email', 'length' => 10, 'minLength' => 3, 'maxLength' => 5],
['g', 'phone'],
['h', 'url', 'length' => 10, 'minLength' => 3, 'maxLength' => 5],
['i', 'in', 'range' => ['A', 'B']],
['j', 'date', 'format' => 'Y-m-d'],
['k', 'compare', 'compareAttribute' => 'a'],
['l', 'match', 'pattern' => '/^[\w]{1,30}$/'],
['m', 'call', 'callback' => [$this, 'check']],
['n', 'file', 'mimes' => ['audio/mp3', 'video/mp4'], 'maxSize' => 1024 * 1],
['r', 'image', 'mimes' => ['image/gif', 'image/jpeg', 'image/png'], 'maxSize' => 1024 * 1],
];
}
// 自定义验证
public function check($attributeValue)
{
return true;
}
// 场景
public function scenarios()
{
return [
'test' => ['required' => ['a', 'b', 'c', 'd'], 'optional' => ['e']],
];
}
// 属性消息
public function attributeMessages()
{
return [
//'a' => '只能为数字.',
//'b' => '只能为小数.',
//'c' => '只能为字母.',
//'d' => '只能为字母与数字.',
//'e' => '长度只能为1~15位.',
];
}
// 属性标签
public function attributeLabels()
{
return [
//'a' => '参数A',
//'b' => '参数B',
//'c' => '参数C',
//'d' => '参数D',
//'e' => '参数E',
];
}
// 操作数据库
public function save()
{
$tableModel = new \web\common\model\TableModel();
$tableModel->insert([
'a' => $this->a,
]);
}
}