zend framework 2-使用验证器比较2个输入? [英] zend framework 2 - compare 2 inputs using validator?
本文介绍了zend framework 2-使用验证器比较2个输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是zend Framework 2的新手,我有一个问题需要比较以工厂支持的形式进行的两个输入.我的情况如下:
I'm new to zend framework 2 and I have a question on comparing two inputs in the factory-backed form. My scenario is like following:
我想比较两个输入,例如$startDate
和$endDate
.我想验证$startDate
总是小于$endDate
.我要怎么做呢?例如:
I want to compare two inputs, for example, $startDate
and $endDate
. I want to validate that $startDate
is always less than $endDate
. How I'm going to do this? For example:
$inputFilter->add($factory->createInput(array(
'name' => 'startDate',
'required' => true,
'validators' => array(
array(
'name' => 'LessThan',
'options' => array(
'max' => $endDate,
),
),
),
)));
仅供参考,我正在关注《相册》教程,并且在classTable.php
中创建了$inputFilter
.
FYI, I'm following the Album tutorial and the $inputFilter
is created in the classTable.php
.
谢谢
推荐答案
感谢Crisp!我用类似的方法解决了这个问题:
Thanks to Crisp! I solved it with something similar:
$inputFilter->add($factory->createInput(array(
'name' => 'startDate',
'required' => true,
'name' => 'Callback',
'options' => array(
'message' => array(
Callback::INVALID_VALUE => 'Invalid period is given.',
),
'callback' => function($value, $context=array()) {
return $value < $context['endDate'];
},
),
)));
这篇关于zend framework 2-使用验证器比较2个输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文