如何将一些数据传递给 ValidationFilter?[禅2] [英] How can i pass some data to a ValidationFilter? [Zend 2]
问题描述
我在 Zend 1 中有一个像 Db_NoRecordExists 这样的 ValidationFilter.但在某些情况下,已经存在具有相同值的记录是可以的 - 例如,当我想更新某些数据时.也许更新后用户名仍然相同.但是后来我的 ValidationFilter 给出了一个错误.现在我可以使用诸如排除 ID XYZ"之类的东西.但是如何将这些 ID 传递给验证过滤器?
I have got a ValidationFilter like Db_NoRecordExists in Zend 1. But in some cases it's okay that there is already a record with the same value - for example when i want to update some data. Maybe the username would be still the same after updating. But then my ValidationFilter gives an error. Now i could use something like "exclude ID XYZ". But how can i pass that IDs to the validationfilter?
谢谢!
推荐答案
使用 setValidationGroup()
方法告诉你的表单它应该关心哪些字段.
Use the setValidationGroup()
method to tell your form which fields it should care about.
例如,如果您的表单有 3 个字段,分别名为 username
、email
和 country
,并且您不需要验证 username
因为它不会被改变,你可以在你的控制器中执行以下操作(假设 $form
是你的表单的一个实例)
eg if your form had 3 fields named username
, email
and country
, and you don't need to validate username
because it's not going to be changed, you can do the following in your controller (assuming $form
is an instance of your form)
$form->setValidationGroup(array(
'email',
'country',
));
这篇关于如何将一些数据传递给 ValidationFilter?[禅2]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!