John Davidson

zend framework - PHP Laminas DoctrineObjectInputFilter get value of other property in Callback input filter

0 comments
Message:


I am working with Laminas DoctrineObjectInputFilter and want to get value of other property in Callback input filter like this code is in init function of Filter class which extends DoctrineObjectInputFilter


// input filter whose value is required
$this->add([
'name' => 'name',
'allow_empty' => false,
'filters' => []
]);
// Input filter in which I want value of input name
$this->add([
'name' => 'value',
'allow_empty' => true,
'filters' => [
[
'name' => 'Callback',
'options' => [
'callback' => function ($value) {
$name = // want to get property name value here

if (key_exists($name, $this->applicationConfig) && gettype($value) === 'string') {
return trim(strip_tags($value));
}
else {
return trim($value);
}

return $value;
},
],
],
],
]);

have checked $this->getRawValues() but its returning null for all inputs.



My Answer:
add([
'name' => 'required_property',
'required' => true,
]);

// input filter with callback to validate based on value of 'required_property'
$this->add([
'name' => 'other_property',
'required' => true,
'validators' => [
[
'name' => 'Callback',
'options' => [
'callback' => function ($value, $context) {
$requiredPropertyValue = $context['required_property'];
// do something with $requiredPropertyValue
return true; // return true if validation passes
},
],
],
],
]);

Rate this post

3 of 5 based on 2947 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us