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?
Nottrim
As 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', ];