search

Home  >  Q&A  >  body text

How does thinkphp6 use the validator to output information to the front-end page?

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];

}

冰点儿冰点儿1673 days ago1114

reply all(2)I'll reply

  • Guanhui

    Guanhui2020-05-04 10:42:10

    微信截图_20200504104518.png

    reply
    0
  • 冰点儿

    冰点儿2020-04-29 22:07:26

    <?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

    reply
    0
  • Cancelreply