From 57bca30e914e6584e7b6f13848f456264ac0a285 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 17 Dec 2014 10:29:13 +0100 Subject: [PATCH] added tip about filter validator --- docs/guide/tutorial-core-validators.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/guide/tutorial-core-validators.md b/docs/guide/tutorial-core-validators.md index ec1a14a45c..92fbc5aad9 100644 --- a/docs/guide/tutorial-core-validators.md +++ b/docs/guide/tutorial-core-validators.md @@ -290,7 +290,17 @@ back to the attribute being validated. Note that if the filter cannot handle array input, you should set this property to be true. Otherwise some PHP error might occur. -> Tip: If you want to trim input values, you may directly use [trim](#trim) validator. +> Tip: If you want to trim input values, you may directly use the [trim](#trim) validator. + +> Tip: There are many PHP functions that have the signature expected for the `filter` callback. +> For example to apply type casting (using e.g. [intval](http://php.net/manual/en/function.intval.php), +> [boolval](http://php.net/manual/en/function.boolval.php), ...) to ensure a specific type for an attribute, +> you can simply specify the function names of the filter without the need to wrap them in a closure: +> +> ```php +> ['property', 'filter', 'filter' => 'boolval'], +> ['property', 'filter', 'filter' => 'intval'], +> ``` ## [[yii\validators\ImageValidator|image]]