mirror of
https://github.com/yiisoft/yii2.git
synced 2025-12-15 10:50:45 +08:00
Fix #20642: Pass $model and $attribute in Compare Validator's compareValue property closure
This commit is contained in:
@@ -57,8 +57,17 @@ class CompareValidator extends Validator
|
||||
*/
|
||||
public $compareAttribute;
|
||||
/**
|
||||
* @var mixed the constant value to be compared with. When both this property
|
||||
* and [[compareAttribute]] are set, this property takes precedence.
|
||||
* @var mixed the constant value to be compared with or an anonymous function
|
||||
* that returns the constant value. When both this property and
|
||||
* [[compareAttribute]] are set, this property takes precedence.
|
||||
* The signature of the anonymous function should be as follows,
|
||||
*
|
||||
* ```
|
||||
* function($model, $attribute) {
|
||||
* // compute value to compare with
|
||||
* return $value;
|
||||
* }
|
||||
* ```
|
||||
* @see compareAttribute
|
||||
*/
|
||||
public $compareValue;
|
||||
@@ -144,7 +153,7 @@ class CompareValidator extends Validator
|
||||
}
|
||||
if ($this->compareValue !== null) {
|
||||
if ($this->compareValue instanceof \Closure) {
|
||||
$this->compareValue = call_user_func($this->compareValue);
|
||||
$this->compareValue = call_user_func($this->compareValue, $model, $attribute);
|
||||
}
|
||||
$compareLabel = $compareValue = $compareValueOrAttribute = $this->compareValue;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user