If we had one Settings class , We need to validate the data submitted by the form .

First write a data verification method :
/** * Validator * @param $param array|object Validated data * @param $action string Method name *
@return bool bool */ private function settingsValidate($param,$action) {
$validate = $this->getValidateBase(Request()->controller()); if($validate
instanceof Settingss){ # Batch verification of data legality $settingsValidate = $validate->scene($action)
->batch(true)->check($param); if (!$settingsValidate) { return $this->
ServerResponse::createByError($validate->getError()); } return $validate->
hasScene($action); } return false; }
$this->getValidateBase(Request()->controller());
This is actually a call to a method in the parent class , Similar factory design pattern , Let's look at the parent class base In getValidateBase() Method of writing :

Then we do scene verification , The name is ¥action . The name is the same as the name of the current method . for example settings How to write a scene in verifier :

And we do batch validation batch(true), As long as certain conditions are not met , It will pop up error prompts together , Not a single tip .
# Batch verification of data legality $settingsValidate = $validate->scene($action)->batch(true)->check(
$param);
When validation fails , We sent out error messages :
return $this->ServerResponse::createByError($validate->getError());
If all the fields meet the requirements , So let's go back true That's it . Otherwise, return false.

At this point, a verification method is completed .

Then we can call this method directly in the controller to complete the data verification :
$this->settingsValidate($param,$action);
think you !

Technology
©2019-2020 Toolsou All rights reserved,
The 11th Blue Bridge Cup python The real topic of the University Group National Games JavaSwing To achieve a simple Lianliankan games 【Spring Source code analysis 】42-@Conditional Detailed explanation element-ui Step on pit record 2019PHP Interview questions ( Continuously updated )PHPJava Misunderstanding —— Method overloading is a manifestation of polymorphism ? First issue 500 100 million , Set up a new Department , What is Tencent going to do ? Google chrome The browser can't open the web page , But what if other browsers can open it ? Regression of dependent variable order categories (R language )【Golang Basic series 10 】Go language On conditional sentences if