Download the PHP package laxity7/yii2-trim-behavior without Composer
On this page you can find all versions of the php package laxity7/yii2-trim-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laxity7/yii2-trim-behavior
More information about laxity7/yii2-trim-behavior
Files in laxity7/yii2-trim-behavior
Package yii2-trim-behavior
Short Description Behavior that truncates all spaces and other characters in all attributes in a model before validate
License MIT
Homepage https://github.com/laxity7/yii2-trim-behavior
Informations about the package yii2-trim-behavior
Yii2 TrimBehavior
This behavior automatically truncates all spaces and other characters in all attributes in a model before validate. The easiest way is to add this behavior to the parent class so that all attributes are always trimmed.
Note: Behavior automatically skips any non-string and empty values.
Install
Install via composer
Or you may add dependency manually in composer.json:
How to use
To use TrimBehavior, insert the following code to your Model/ActiveRecord class:
You can also pass the following parameters:
- fields
string[]
(by default[]
) List of fields to process. By default all fields. - mask
string
(by default' \t\n\r '
) Simply list all characters that you want to be stripped. You can use TrimBehavior::DEFAULT_MASK to combine your characters and defaults - once
string[]
(by defaulttrue
) Run the behavior once and detach after.
So, the complete list of settings will look like this:
If you want to trim only certain fields in a certain class, then better to use the filter in rules of validation