From 523e4b324b6b2b5352ed56887c323217aa93099e Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 7 Aug 2020 11:38:10 +0300 Subject: [PATCH] Fix #18175: Add upgrade note for 2.0.36 about inline validator defined as closure --- framework/UPGRADE.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index 5d9e903e4d..ec571a5077 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -96,6 +96,16 @@ Upgrade from Yii 2.0.35 // $current === 'second' (on second iteration) } ``` + +* `$this` in an inline validator defined as closure now refers to model instance. If you need to access the object registering + the validator, pass its instance through use statement: + + ```php + $registrar = $this; + $validator = function($attribute, $params, $validator, $current) use ($registrar) { + // ... + } + ``` * If you have any controllers that override the `init()` method, make sure they are calling `parent::init()` at the beginning, as demonstrated in the [component guide](https://www.yiiframework.com/doc/guide/2.0/en/concept-components).