Although I would have some PHP basic grammar, I set the data, I wrote the controller layer, not using the API way, the company is to exercise me, so just do, basically things are with the framework of their own, and do not have to encapsulate these things, so the programming ideology, but also very deficient, So I have to imitate someone else's code first.
Problem:
How to customize the validator class, and how to use custom rules;
Whether it is a validator, or interceptors, filters, are to inherit the corresponding class, as long as the inheritance is the corresponding to what validator, interceptor ... The
eg
1. Custom Validator Classes
Class Validatecustom extends Validate
{
Write the method name directly in the back;
protected $rule = [
' id ' = ' require| Ispositiveinteger'
];
/**
* Determine if a number is a positive integer
*/
Ispositiveinteger ($value, $rule = ", $data =", $field = ")
{
if (Is_numeric ($value) && is_int ($value + 0) && ($value + 0) > 0) {
return true;
} else {
Return $field. ' must be a positive integer ';
}
}
}
2. Use of other classes
$data = [
' id ' = $id
];
Validator
$validate = new Validatecustom ();
Perform batch Validation
$result = $validate->batch ()->check ($data);
Output Error Hints
Var_dump ($validate->geterror ());
thinkphp5.0 Custom Validator