Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用 Symfony 2 验证组件来验证我的表单而不使用表单组件,因为我更喜欢手动创建自己的 HTML 表单。如何将手动表单中的数据绑定到实体,以便在控制器中验证该实体?
只需通过$request->request参数包并使用模型的设置器来设置数据。然后您可以使用该validator服务来验证实体:
$request->request
validator
$constraintViolationList = $this->get('validator')->validate($entity);
如果$constraintViolationList不为空,则实体无效。
$constraintViolationList
顺便说一句,我相信 Symfony 表单组件可以说是框架中最重要的部分。我建议你重新考虑你的立场。