$formFactory = new Symfony\Component\Form\FormFactory();
//build your "post" data from your submitted content via api
$data = json_decode($request->getContent(), TRUE);
//build your Form and Entity objects.
$formType = new Path\To\CatForm(); //for example
$entity = new Path\To\CatEntity();
$parameters = array();
$method = 'POST';
$form = $formFactory->create($formType, $entity, ['method' => $method]);
$form->submit($parameters, ($method == 'PATCH' ? false : true));
if ($form->isValid()) {
//do stuff
}
1条答案
按热度按时间vecaoik11#
我建议仍然使用Form来处理验证,您可以手动模拟提交:http://symfony.com/doc/current/form/direct_submit.html#calling-form-submit-manually
一个非常简单的例子如下所示。