How does thinkphp6 use the validator to output information to the front-end page?
冰点儿
冰点儿 2020-04-29 21:08:25
0
2
1110

public function checkLogin (Request $request)

{

$status = 0;

$result = 'Default value';

$ data = $request->param();

$result = validate(UserValidate::class)->check($data);

// If it is found during the test that the field verification fails, the execution will not proceed.

If($result){

$result = 'Verification successful';

$status = 1;

#} Else {

# Validate ()-& GT; Geterror ();

##}

return ['status'=>$status, 'message'=>$result, 'data'=>$data];

}

冰点儿
冰点儿

reply all(2)
凉官灰

微信截图_20200504104518.png

冰点儿

<?phpnamespace app\validate;use think\Validate;class User extends Validate{

protected $rule = [

'name|username' => 'require' ,    

'password|password' => 'require',  

'verify|verification code' => 'require|captcha', 

];  protected $ message = [

'name|Username.require' => 'Name must be filled in',

'password|Password.require' => 'Password required',

'verify.require' => 'Verification code must be filled in',

'verify.captcha' => 'Verification code error',

];}

============================================ =======================

<?php

namespace app\facade;

use think\Facade;/*** */

class User extends Facade{

protected static function getFacadeClass()

{

return 'app\validate\User';

}

}

====================== ======================================

public function checkLogin (Request $ request) {  

$status = 0 ;    

$result = 'Default value';    

$data = $request->param();                            = new UserValidate; // $result = $validate->check($data); if(UserFacade::check($data)){

$result = 'Verification successful';

$status = 1; 'message'=>$result, 'data'=>$data];

}}

Customized message None display

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template