本文整理汇总了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;
}
示例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;
}
示例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;
}
}
}
}
示例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);
}