验证 ¶
- 验证注解
验证规则 ¶
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 () );
}