Yii2 Dynamic attach Behavior to parent class yii\validators\Validator inheritance does not work for all child Validation's class

Hello colleagues.

Pls help me

I want to attach “MyValidationBehavior” (Yii2 Behavior) for all Validation’s class in my project dynamically.

I wrote the code and it work fine.

I attach "MyValidationBehavior" for all builtInValidator through foreach.

        foreach (\yii\validators\Validator::$builtInValidators as $builtInValidator) {


                ["as $builtInValidator" => ['class' => MyValidationBehavior::className(),]]);


But I want to attach “MyValidationBehavior” Dynamically just for parent class “Validator” and I hope that Validator’ child class will have this “MyValidationBehavior” too.

What do you think Is it possible?

Any questions pls ask me, I’ll try answer.

Thank you.



I tried to attach "MyValidationBehavior" just for parent class "\yii\validators\Validator" but without success,

Validator’ child class do not inherit this “MyValidationBehavior”.[/b]

For example:

        $container = \Yii::$container;

        //option 1


             ["as Validator" => ['class' => MyValidationBehavior::className(),]]);

        //option 2

        $validator = $container->get('yii\validators\Validator');

        $validator->attachBehavior('Validator', MyValidationBehavior::className());