我使用最新版本的 Laminas。我有一个通过添加到表单的init()
字段集,并将其设置为基本字段集。如果您在字段集中定义getInputFilterSpecification()
,在更新 Laminas 框架之前(我必须承认,我有几个月没有更新),我可以通过在字段集内部调用来检索字段集输入的过滤$this->get('someName')->getValue()
值getInputFilterSpecification()
。这非常方便,因为如果您有一个通过工厂初始化的复杂验证器,并且您想将其他输入的值传递给该验证器以实现复杂逻辑,您只需将所需的输入值分配给'options'
验证器,如下所示:
'someInputName' => [
'required' => false,
'filters' => [
['name' => StripTags::class],
['name' => StringTrim::class],
...
],
'validators' => [
['name' => NotEmpty::class],
[
'name' => AComplexValidator::class,
'options' => [
'parameter1' =>
$this->get('otherName1')->getValue(),
'parameter2' =>
$this->get('otherName2')->getValue(),
],
],
...
],
],
并且已经获得了输入的过滤值parameter1
,parameter2
因此无需在验证器中重新处理值。现在那里只提供原始的、未过滤的值$this->get('otherName2')->getValue()
。
有没有办法为验证器工厂提供字段集输入的过滤值?还是我这样做完全错误?