Yii2 user data verification problems

Source: Internet
Author: User
Write rules in the rules method of a model, {code ...} it should be said that the content should be filtered like the trim function. In fact, the error "ReflectionExceptionClassstrip_tagsdoesnotexist" is reported why trim is used as a function, but strip_tags is used as a class... write rules in the rules method of a model,

public function rules()    {        return [            [['title','description','keywords'],'strip_tags']        ];    }

It is reasonable to say that the trim function is the same as the trim function to filter the content, but an error is actually returned.
ReflectionException
Class strip_tags does not exist
Why is trim treated as a function but strip_tags treated as a class?

Reply content:

Write rules in the rules method of a model,

public function rules()    {        return [            [['title','description','keywords'],'strip_tags']        ];    }

It is reasonable to say that the trim function is the same as the trim function to filter the content, but an error is actually returned.
ReflectionException
Class strip_tags does not exist
Why is trim treated as a function but strip_tags treated as a class?

NottrimAs a function.

    public static $builtInValidators = [        'boolean' => 'yii\validators\BooleanValidator',        'captcha' => 'yii\captcha\CaptchaValidator',        'compare' => 'yii\validators\CompareValidator',        'date' => 'yii\validators\DateValidator',        'default' => 'yii\validators\DefaultValueValidator',        'double' => 'yii\validators\NumberValidator',        'each' => 'yii\validators\EachValidator',        'email' => 'yii\validators\EmailValidator',        'exist' => 'yii\validators\ExistValidator',        'file' => 'yii\validators\FileValidator',        'filter' => 'yii\validators\FilterValidator',        'image' => 'yii\validators\ImageValidator',        'in' => 'yii\validators\RangeValidator',        'integer' => [            'class' => 'yii\validators\NumberValidator',            'integerOnly' => true,        ],        'match' => 'yii\validators\RegularExpressionValidator',        'number' => 'yii\validators\NumberValidator',        'required' => 'yii\validators\RequiredValidator',        'safe' => 'yii\validators\SafeValidator',        'string' => 'yii\validators\StringValidator',        'trim' => [            'class' => 'yii\validators\FilterValidator',            'filter' => 'trim',            'skipOnArray' => true,        ],        'unique' => 'yii\validators\UniqueValidator',        'url' => 'yii\validators\UrlValidator',        'ip' => 'yii\validators\IpValidator',    ];

Parent class yii/base/Model: createValidators. You can refer to this method to generate the validator method.
Traverse rules and Judge $ rule [1], which is equivalent to the fields 'trim' and 'strip _ tags '.
1. Whether it is an anonymous Function($rule instanceof \Closure)Or is it a subclass method?
2. determine whether an existing validator exists.

public static $builtInValidators = [        'boolean' => 'yii\validators\BooleanValidator',        'captcha' => 'yii\captcha\CaptchaValidator',        'compare' => 'yii\validators\CompareValidator',        'date' => 'yii\validators\DateValidator',        'default' => 'yii\validators\DefaultValueValidator',        'double' => 'yii\validators\NumberValidator',        'each' => 'yii\validators\EachValidator',        'email' => 'yii\validators\EmailValidator',        'exist' => 'yii\validators\ExistValidator',        'file' => 'yii\validators\FileValidator',        'filter' => 'yii\validators\FilterValidator',        'image' => 'yii\validators\ImageValidator',        'in' => 'yii\validators\RangeValidator',        'integer' => [            'class' => 'yii\validators\NumberValidator',            'integerOnly' => true,        ],        'match' => 'yii\validators\RegularExpressionValidator',        'number' => 'yii\validators\NumberValidator',        'required' => 'yii\validators\RequiredValidator',        'safe' => 'yii\validators\SafeValidator',        'string' => 'yii\validators\StringValidator',        'trim' => [            'class' => 'yii\validators\FilterValidator',            'filter' => 'trim',            'skipOnArray' => true,        ],        'unique' => 'yii\validators\UniqueValidator',        'url' => 'yii\validators\UrlValidator',    ];

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.