我正在使用 Laminas DoctrineObjectInputFilter
并希望获取回调输入过滤器中其他属性的值,就像此代码位于 Filter
类的 init 函数中,该类扩展了 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; }, ], ], ], ]);
已检查 $this->getRawValues()
但它对所有输入返回 null。
P粉8422150062024-03-29 13:22:50
有点晚了,但我猜您正在搜索$context
。由于 name 的值位于同一个 InputFilter
实例中,因此您只需在回调函数中使用 $context
即可。
add([ 'name' => 'name', 'required' => true, 'allow_empty' => false, 'filters' => [ [ 'name' => StripTags::class ], [ 'name' => StringTrim::class ], [ 'name' => ToNull::class, 'options' => [ 'type' => ToNull::TYPE_STRING, ], ], ], ]); $this->add([ 'name' => 'value', 'required' => true, 'allow_empty' => true, 'filters' => [], 'validators' => [ [ 'name' => Callback::class, 'options' => [ 'callback' => function($value, $context) { $name = $context['name']; ... }, ], ], ], ]); } }