S
S
Sergey Beloventsev2017-08-17 17:03:00
Yii
Sergey Beloventsev, 2017-08-17 17:03:00

What is the proper way to use yii eachvalidator?

the crux of the matter is the following I use select2 with multiple choice I get in the query the following array
should get

'thema' => [ 0 => 'детктив' 1 => 'фантасика' 2 => 'роман' ]

I need at least three objects but no more than 7 to be selected, I use each validator as follows, but I get an error
['thema','each','rule'=>['min'=>2,'max'=>5]]
Invalid validation rule: a rule must be an array specifying validator type.

and the array looks like this, why don't you tell me? And how right?
'thema ' => [ 0 => '1' 1 => '2' 2 => '4' ]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-08-17
@Sergalas

Good afternoon.
It is unlikely that you will succeed, because the error says that "the rule must be an array that defines the type of the validator."
Example:

['thema','each','rule'=>['integer']]; // определяет, что каждое значение должно быть целым числом
['thema','each','rule'=>['match', 'pattern' => '/[a-z]/is']]; // проверяет каждое переданное значение на соответствие введённых символов

If it comes to that, then, I think, a validator that you create yourself will help, which will check the number of elements in the array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question