How can i pass some data to a ValidationFilter? [Zend 2]

送分小仙女□ 提交于 2019-12-11 14:10:43

问题


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?

Thank You!


回答1:


Use the setValidationGroup() method to tell your form which fields it should care about.

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',
));


来源:https://stackoverflow.com/questions/15300105/how-can-i-pass-some-data-to-a-validationfilter-zend-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!