YII2 issues with User data validation

Source: Internet
Author: User
Write the rules in a model's Rules method,

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

This is supposed to be the same as the trim function, the content is filtered, in fact, the error
Reflectionexception
Class Strip_tags does not exist
Why use trim as a function, but strip_tags as a class, what's going on?

Reply content:

Write the rules in a model's Rules method,

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

This is supposed to be the same as the trim function, the content is filtered, in fact, the error
Reflectionexception
Class Strip_tags does not exist
Why use trim as a function, but strip_tags as a class, what's going on?

is not treated as a trim function.

    public static $builtInValidators = [' Boolean ' = ' yii\validators\booleanvalidator ', ' captcha ' = ' Yii\captcha\captchavalidator ', ' compare ' = ' yii\validators\comparevalidator ', ' date ' = ' Yii\validat Ors\datevalidator ', ' default ' = ' yii\validators\defaultvaluevalidator ', ' double ' = ' yii\validators\n '         Umbervalidator ', ' 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\vali ' Dators\rangevalidator ', ' integer ' = [' class ' = ' yii\validators\numbervalidator ', ' in Tegeronly ' = True,], ' match ' = ' yii\validators\regularexpressionvalidator ', ' number ' = ' Yii\validators\numbervalIdator ', ' required ' = ' yii\validators\requiredvalidator ', ' safe ' = ' yii\validators\safevalidator ', ' String ' = ' yii\validators\stringvalidator ', ' trim ' and ' = ' class ' + ' yii\validators\filt Ervalidator ', ' filter ' = ' trim ', ' skiponarray ' = = True,], ' unique ' = ' yii\ ' Validators\uniquevalidator ', ' url ' = ' yii\validators\urlvalidator ', ' ip ' = = ' Yii\validators\ipvalidat or ',];

The parent class yii/base/model::createvalidators, the landlord can see this method concretely, generate the validator method.
Traversing rules, judging $rule[1], is also equivalent to ' trim ', ' strip_tags ' these fields
1, whether it is an anonymous function ($rule instanceof \Closure) or whether it is a subclass of methods
2. Determine if an existing authenticator is present

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\numbe '        Rvalidator ', ' each ' = ' yii\validators\eachvalidator ', ' email ' = ' yii\validators\emailvalidator ', ' Exist ' = ' yii\validators\existvalidator ', ' file ' = ' yii\validators\filevalidator ', ' Filter ' =&G T ' Yii\validators\filtervalidator ', ' image ' = ' yii\validators\imagevalidator ', ' in ' = ' yii\validators\ ' RangeValidator ', ' integer ' = [' class ' = ' Yii\validators\numbervalidator ', ' Integeron Ly ' = True,], ' match ' = ' yii\validators\regularexpressionvalidator ', ' number ' = ' yii\val Idators\numbervalidator ', ' required ' = ' yii\validators\requiredvalidator ', ' safe ' = ' yii\validators\safevalidator ', ' String ' = ' yii\validators\stringvalidator ', ' trim ' and ' = ' class ' + ' Yii\validators\filterva Lidator ', ' filter ' = ' trim ', ' skiponarray ' = = True,], ' unique ' = ' Yii\vali ' Dators\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.