PHP code example of wekyun / check

1. Go to this page and download the library: Download wekyun/check library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wekyun / check example snippets


php think make:validate Common


1:使用com的场景验证类, 接收id参数,如果没有则默认值为33                 接收参数,并设置默认值
    //  :后面的值为设置的默认值
	Check::check('com', 'id:33');

2:使用com的场景验证类, 接收id参数,id参数为必传,不传就报错               接收必传参数,不传报错
    //  .代表参数必传
	Check::check('com', 'id.');


3:接收多个参数,使用com的场景验证类, 多个参数之间使用英文的 , 分割;
//  .代表参数必传
//  :后面的值为设置的默认值
	Check::check('com', 'id.,name.,age:18');

4:数组使用方式
    //规则都是一样的
    Check::check('com', ['id.','name.','age:18']);


return [
	//默认错误的处理方法
    'err_func' => function ($msg, $err_code) {
        $json = json_encode([
            'msg' => $msg,
            'code' => $err_code,
        ], JSON_UNESCAPED_UNICODE);
        die($json);
    },
    'err_code' => 203,//默认错误的错误码
    //此配置为必须,配置需要使用的验证场景类
    'mapping' => [
        'com' => \app\common\validate\Common::class,
    ],
];