Skip to content
官方QQ交流群
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

验证

  • 验证注解

验证规则

php
protected $rule = [
    'id' => [
        'require', 'number', 'regex' => '/^[1-9]{1}\d{0,9}$/',
    ],
    'resume_mobile' => [
        'require', 'mobile', 'regex' => "/^1[345678]{1}\d{9}$/"
    ],
];
protected $message = [
    'id' => [
        'require' => 'id不能为空',
        'number' => 'id格式错误',
        'regex' => 'id参数错误',
    ],
    
];
// 场景配置
protected $scene = [
    'getById' => ['id'],
    'postData'  =>  [],
    'putById'  =>  ['id', ],
];
protected $rule = [
    'id' => [
        'require', 'number', 'regex' => '/^[1-9]{1}\d{0,9}$/',
    ],
    'resume_mobile' => [
        'require', 'mobile', 'regex' => "/^1[345678]{1}\d{9}$/"
    ],
];
protected $message = [
    'id' => [
        'require' => 'id不能为空',
        'number' => 'id格式错误',
        'regex' => 'id参数错误',
    ],
    
];
// 场景配置
protected $scene = [
    'getById' => ['id'],
    'postData'  =>  [],
    'putById'  =>  ['id', ],
];
  • 常规方式
php
$request_data = ctoRequestOnly ( [
	'goods_id/int', // 商品id
	'omain_id/int', // 订单ID
	'comment_content/string' // 评论内容
] );
$validateForm = new \addons\comA\moduleA\validate\ActivityValidate ();
// 动态规则场景
if(! $validateForm->setScene ( 'VCreateComment', [
	'goods_id',
	'omain_id',
	'comment_content'
] )
	->scene ( 'VCreateComment' )
	->check ( $request_data )){
	sendRespError ( $validateForm->getError () );
}
$request_data = ctoRequestOnly ( [
	'goods_id/int', // 商品id
	'omain_id/int', // 订单ID
	'comment_content/string' // 评论内容
] );
$validateForm = new \addons\comA\moduleA\validate\ActivityValidate ();
// 动态规则场景
if(! $validateForm->setScene ( 'VCreateComment', [
	'goods_id',
	'omain_id',
	'comment_content'
] )
	->scene ( 'VCreateComment' )
	->check ( $request_data )){
	sendRespError ( $validateForm->getError () );
}

参考

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发