我正在使用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']; ... }, ], ], ], ]); } }