vloop/yii2-custom-validators 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vloop/yii2-custom-validators

最新稳定版本:v1.0.2

Composer 安装命令:

composer require vloop/yii2-custom-validators

包简介

Custom validators for Yii2 projects

README 文档

README

rules() {
   return 
       [
          'data',
          ArrayValidator::class,
          'subRules' => [
              [['foo', 'bar'], 'required'],
              [
                  'foo',                                         // associative array
                  ArrayValidator::class,
                  'subRules' => [
                      ['id', 'required'],
                      ['id', 'integer'],
                  ],
              ],
              ['bar', 'string'],
              [
                  'payments',                                     // non-associative array
                  CustomEachValidator::class,
                  'rule' => [
                      ArrayValidator::class,
                      'subRules' => [
                          [['type', 'sum'], 'required'],
                          ['type', 'in', 'range' => [1, 2, 3]],
                          ['sum', 'double'],
                      ],
                  ],
              ],
              [
                  'client',
                  ArrayValidator::class,
                  'subRules' => [                                // using closure inside 'when'. $client - internal validation model
                      ['email', 'required', 'message' => '[email] cannot be blank when [phone] is blank', 'when' => static function($client) {
                          return empty($client->phone);
                      }],
                      ['phone', 'required', 'message' => '[phone] cannot be blank when [email] is blank', 'when' => static function($client) {
                          return empty($client->email);
                      }],
                      ['email', 'email'],
                      ['phone', PhoneInputValidator::class],
                      ['email', function($attribute, $params) {  // Using a closure as a validator. $this - internal validation model
                          if ($this->$attribute === 'test@example.com') {
                              $this->addError("forbidden $attribute value was passed");
                          }
                      }],
                  ],
              ],
          ],
        ]
}

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固