@@ -20,7 +20,7 @@ run: `composer update`
2020
2121- Method 1: create a new class
2222 e.g.
23-
23+
2424``` php
2525
2626 use inhere\validate\Validation;
@@ -34,40 +34,39 @@ run: `composer update`
3434 ['tagId', 'size', 'min'=>4, 'max'=>567], // 4<= tagId <=567
3535 ['title', 'min', 'min' => 40],
3636 ['freeTime', 'number'],
37- ['tagId', 'number', 'when' => function($data)
37+ ['tagId', 'number', 'when' => function($data)
3838 {
3939 return isset($data['status']) && $data['status'] > 2;
4040 }],
41- ['userId', 'number', 'scene ' => 'scene1' ],
42- ['userId', 'int', 'scene ' => 'scene2' ],
41+ ['userId', 'number', 'on ' => 'scene1' ],
42+ ['userId', 'int', 'on ' => 'scene2' ],
4343 ['title', 'customValidator', 'msg' => '{attr} error msg!' ],
4444 ['status', function($status)
45- {
45+ {
4646
4747 if ( .... ) {
4848 return true;
4949 }
5050 return false;
5151 }],
5252 ];
53- }
54-
53+
5554 // custom validator at the class. return a bool.
5655 protected function customValidator($title)
5756 {
5857 // some logic ...
59-
58+
6059 return true; // Or false;
6160 }
62-
61+
6362 // define field attribute's translate.
6463 public function attrTrans()
6564 {
6665 return [
6766 'userId' => '用户Id',
6867 ];
6968 }
70-
69+
7170 // custom validator message, more {@see ValidationTrait::_defaultMessages}
7271 public function messages()
7372 {
@@ -87,7 +86,7 @@ if ( $valid->fail() ) {
8786 return $valid->getErrors();
8887}
8988...
90-
89+
9190```
9291
9392
@@ -97,7 +96,7 @@ if ( $valid->fail() ) {
9796
9897 use inhere\validate\Validation;
9998
100- class SomeClass
99+ class SomeClass
101100 {
102101 public function demo()
103102 {
@@ -111,7 +110,7 @@ if ( $valid->fail() ) {
111110 return $valid->getErrors();
112111 }
113112
114- //
113+ //
115114 // some logic ... ...
116115 }
117116 }
@@ -132,14 +131,14 @@ $valid = Validation::make($_POST,[
132131 ])
133132 ->addValidator('checkTitle',function($title){
134133 // some logic ...
135-
134+
136135 return true; // if validate fail, return false.
137136 }, '{attr} default message!')
138137 ->validate();
139138
140139```
141140
142- ### keywords
141+ ### keywords
143142
144143- scene -- 设置验证场景
145144
@@ -148,15 +147,15 @@ $valid = Validation::make($_POST,[
148147``` php
149148
150149// at a subclass of the Validation class
151- <?php
152-
153- public function rules()
150+ <?php
151+
152+ public function rules()
154153 {
155154 return [
156155 ['title', 'required' ],
157- ['userId', 'number', 'scene ' => 'scene1' ],
158- ['userId', 'int', 'scene ' => 'scene2' ],
159- ['name', 'string', 'scene ' => 'scene1,scene2' ],
156+ ['userId', 'number', 'on ' => 'scene1' ],
157+ ['userId', 'int', 'on ' => 'scene2' ],
158+ ['name', 'string', 'on ' => 'scene1,scene2' ],
160159 ];
161160 }
162161```
@@ -165,7 +164,7 @@ $valid = Validation::make($_POST,[
165164
166165``` php
167166
168- // at logic
167+ // at logic
169168<?php
170169
171170 ...
@@ -184,12 +183,12 @@ $valid = Validation::make($_POST,[
184183``` php
185184
186185// at a subclass of the Validation class
187- <?php
188- public function rules()
186+ <?php
187+ public function rules()
189188 {
190189 return [
191190 ['title', 'required' ],
192- ['tagId', 'number', 'when' => function($data, $validator)
191+ ['tagId', 'number', 'when' => function($data, $validator)
193192 {
194193 return isset($data['status']) && $data['status'] > 2;
195194 }],
@@ -232,7 +231,7 @@ $valid = Validation::make($_POST,[
232231 }]
233232```
234233
235- ### Existing validators
234+ ### Existing validators
236235
237236validator | description | rule example
238237----------|-------------|------------
@@ -252,4 +251,4 @@ validator | description | rule example
252251` in ` | validate in | ` ['id', 'in', 'value' => [1,2,3],] `
253252` string ` | validate string | ....
254253` isArray ` | validate is Array | ....
255- ` callback ` | validate by custom callback | ....
254+ ` callback ` | validate by custom callback | ....
0 commit comments