当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::getActiveValidators方法代码示例

本文整理汇总了PHP中yii\base\Model::getActiveValidators方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getActiveValidators方法的具体用法?PHP Model::getActiveValidators怎么用?PHP Model::getActiveValidators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\base\Model的用法示例。


在下文中一共展示了Model::getActiveValidators方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validateFile

 /**
  * @param UploadedFile $file
  * @return bool
  * @throws InvalidFileUploadException
  */
 protected function validateFile(UploadedFile $file)
 {
     $validators = $this->formModel->getActiveValidators($this->fileAttribute);
     foreach ($validators as $validator) {
         if ($validator->validate($file, $error) === false) {
             throw new InvalidFileUploadException($error);
         }
     }
     return true;
 }
开发者ID:opus-online,项目名称:yii2-file,代码行数:15,代码来源:UploadHandler.php

示例2: getClientValidatorsAttribute

 /**
  * Get client side validators attribute
  * @param \yii\base\Model $model Model
  * @param string $attribute Attribute name
  * @param \yii\web\View $view Current view
  * @return array
  */
 public static function getClientValidatorsAttribute(Model $model, $attribute, $view)
 {
     $validators = [];
     foreach ($model->getActiveValidators($attribute) as $validator) {
         /* @var $validator \yii\validators\Validator */
         $js = $validator->clientValidateAttribute($model, $attribute, $view);
         if ($validator->enableClientValidation && $js != '') {
             if ($validator->whenClient !== null) {
                 $js = "if (({$validator->whenClient})(attribute, value)) { {$js} }";
             }
             $validators[] = $js;
         }
     }
     return $validators;
 }
开发者ID:kalibao,项目名称:magesko,代码行数:22,代码来源:ClientSideValidator.php

示例3: normalizeMaxLength

 /**
  * If `maxlength` option is set true and the model attribute is validated by a string validator,
  * the `maxlength` option will take the value of [[\yii\validators\StringValidator::max]].
  * @param Model $model the model object
  * @param string $attribute the attribute name or expression.
  * @param array $options the tag options in terms of name-value pairs.
  */
 private static function normalizeMaxLength($model, $attribute, &$options)
 {
     if (isset($options['maxlength']) && $options['maxlength'] === true) {
         unset($options['maxlength']);
         $attrName = static::getAttributeName($attribute);
         foreach ($model->getActiveValidators($attrName) as $validator) {
             if ($validator instanceof StringValidator && $validator->max !== null) {
                 $options['maxlength'] = $validator->max;
                 break;
             }
         }
     }
 }
开发者ID:Kest007,项目名称:yii2,代码行数:20,代码来源:BaseHtml.php

示例4: activeTextInput

 /**
  * Generates a text input tag for the given model attribute.
  * This method will generate the "name" and "value" tag attributes automatically for the model attribute
  * unless they are explicitly specified in `$options`.
  * @param Model $model the model object
  * @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
  * about attribute expression.
  * @param array $options the tag options in terms of name-value pairs. These will be rendered as
  * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
  * See [[renderTagAttributes()]] for details on how attributes are being rendered.
  * The following special options are recognized:
  *
  * - maxlength: integer|boolean, when `maxlength` is set true and the model attribute is validated
  *   by a string validator, the `maxlength` option will take the value of [[\yii\validators\StringValidator::max]].
  *   This is available since version 2.0.3.
  *
  * @return string the generated input tag
  */
 public static function activeTextInput($model, $attribute, $options = [])
 {
     if (isset($options['maxlength']) && $options['maxlength'] === true) {
         unset($options['maxlength']);
         $attrName = static::getAttributeName($attribute);
         foreach ($model->getActiveValidators($attrName) as $validator) {
             if ($validator instanceof StringValidator && $validator->max !== null) {
                 $options['maxlength'] = $validator->max;
                 break;
             }
         }
     }
     return static::activeInput('text', $model, $attribute, $options);
 }
开发者ID:albertinho88,项目名称:jlweb,代码行数:32,代码来源:BaseHtml.php


注:本文中的yii\base\Model::getActiveValidators方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。