What is the right way of using AllowList. I am trying to use it as follows. My question is how do I pass the list of values.
$inputFilter->add([
'name' => 'my-dsc-type',
'required' => true,
'allow_empty' => false,
'filters' => [
[
'name' => AllowList::class,
'list' => ['1','2'],
],
],
]);
I think it is:
$inputFilter->add([
'name' => 'my-dsc-type',
'required' => true,
'allow_empty' => false,
'filters' => [
[
'name' => new AllowList(['1','2'])
],
],
]);
ezkimo
3
You can use an options
key for every filter in your configuration.
inputFilter->add([
'name' => 'my-dsc-type',
'required' => true,
'allow_empty' => false,
'filters' => [
[
'name' => AllowList::class,
'options' => [
'list' => ['1', '2'],
'strict' => true,
],
],
],
]);
… or as constructor parameter:
$allowList = new \Laminas\Filter\AllowList([
'list' => ['allowed-1', 'allowed-2']
]);
echo $allowList->filter('allowed-2'); // => 'allowed-2'
echo $allowList->filter('not-allowed'); // => null
Last example taken from the official laminas documentation.