[英]Access the set data for logic in Laminas filter?
I am using Mezzio/Laminas (newer version of Zend) and want to check whether an id is less than a number.我正在使用 Mezzio/Laminas(Zend 的较新版本)并想检查 id 是否小于数字。 If it is not, another form element is required.如果不是,则需要另一个表单元素。 Is it possible to access the set data in a laminas-filter in any way?是否可以以任何方式访问层过滤器中的设置数据?
In your input filter class, you can override setData在您的输入过滤器 class 中,您可以覆盖 setData
public function setData($data)
{
// your custom logic here
return parent::setData($data);
}
In the example below I added an example of how to edit an already defined input or add a new input definition在下面的示例中,我添加了一个示例,说明如何编辑已定义的输入或添加新的输入定义
public function setData($data)
{
$type = array_key_exists('type', $data) ? $data['type'] : null;
switch($type) {
case 'CASE_ONE':
$this->get('someAlreadyDefinedElement')->setRequired(false);
$this->add([
'name' => 'someOtherElement',
'required' => true,
'validators' => [
[
'name' => 'Date',
'options' => [
'format' => \DateTime::ISO8601,
],
],
],
]);
break;
case 'SOME_OTHER_CASE':
// some other logic
break;
}
return parent::setData($data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.