Symfony 后端:插入前对字段进行特定测试
我正在使用 symfony 的管理生成器, 在“新”界面中,我想在插入数据库之前测试一个特定字段,如果它没有通过,我会将用户返回到同一界面,直到他获得正确的值! 谁能告诉我如何做到这一点?
对于对我的问题投否决票的人:我不是在寻找一个简单的验证器,我想要的是一个 url 字段,我检查它的 IP 是否存在于我的数据库中,然后添加它(避免添加所有外部 url)
am using the symfony's admin generator,
in the "new" interface, i have one specific field that i want to test before insert into database, and if it doesn't pass i return the user to the same interface until he gets the right value !
can any body tell me how it can be done?
for the one who voted down on my question : am not looking for a simple validator, what i want is that a url field i check whether it IP existe in my DB and then add it (avoid adding all external urls)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读您的问题和您对反对票的评论,很明显您需要一个自定义验证器类。您需要创建一个自定义验证器 [链接 ] 并让它做你想做的事。
我从你的问题中了解到,你想从 URL 获取 IP 地址并检查该 IP 地址是否存在于数据库中,Symfony 没有内置的验证器来实现类似的功能。这就是为什么您需要自己创建验证器。
Reading your question an your comment on the negative vote, is clear that you need a custom validator class. You need to create a custom validator [link] and make it do what you want it to do.
What I understood from your question, is that you want to get the IP address from a URL and check if the IP address exists in the DB, Symfony doesn't have a built in validator for something like this. That is why you need to create the validator yourself.