From 7b8289275f83421a45d35596a0fdf44bf8c91543 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 18 Dec 2013 16:15:21 +0100 Subject: [PATCH] Quick example of inline validator (original doc did not mention inline validator) --- docs/guide/validation.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/guide/validation.md b/docs/guide/validation.md index 431300f..1b1e92e 100644 --- a/docs/guide/validation.md +++ b/docs/guide/validation.md @@ -110,6 +110,19 @@ Validates that the attribute value is among a list of values. - `strict` whether the comparison is strict (both type and value must be the same). _(false)_ - `not` whether to invert the validation logic. _(false)_ +### `inline`: [[InlineValidator]] + +Uses a custom function to validate the attribute. You need to define a public method in your model class which will evaluate the validity of the attribute. For example, if an attribute needs to be divisible by 10. In the rules you would define: `['attributeName', 'myValidationMethod'],`. + +Then, your own method could look like this: +```php +public function myValidationMethod($attribute) { + if(($attribute % 10) != 0) { + $this->addError($attribute, 'cannot divide value by 10'); + } +} +``` + ### `integer`: [[NumberValidator]] Validates that the attribute value is an integer number.