简体   繁体   English

如何使用框架 symfony 在更新项目的 dados 之前添加验证?

[英]How add verifications before update dados of an item using framework symfony?

I need to check information when updating an item, to know if saving is allowed or not.我需要在更新项目时检查信息,以了解是否允许保存。 This must be done in the backend after the user have clicked on 'UPDATE' button.这必须在用户单击“更新”按钮后在后端完成。 I'm using Symfony and the existing methods in CRUDController.我正在使用 Symfony 和 CRUDController 中的现有方法。 Is there any method I can add in Controller or Entity so I can add code that does this check before saving?有没有什么方法可以添加到 Controller 或 Entity 中,这样我就可以添加在保存之前执行此检查的代码?

You have multiple ways to set validation with Symfony.您可以通过多种方式使用 Symfony 设置验证。

If I understand well your question, you maybe need to look at the callbacks如果我很好地理解你的问题,你可能需要查看回调

https://symfony.com/doc/current/reference/constraints/Callback.html https://symfony.com/doc/current/reference/constraints/Callback.html

The purpose is to create custom validation with dedicated functions (like only saving an item if it meets some requirement.)目的是创建具有专用功能的自定义验证(例如仅在满足某些要求时才保存项目。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM