четверг, 2 августа 2018 г.

Symfony how to bind request data to form without HTML

When you want to bind data to form (for example in your REST application) as in FOSRestBundle, but after handleRequest() you doesn't have submitted data, try to map it with

$this->get('form.factory')->createNamed('', MyFormType::class, $dummy, ['csrf_protection' => false]);

, where first parameter is empty string, the second is form, $dummy is for model or entity object. So you can use form validation in simple Symfony action.

Комментариев нет:

Отправить комментарий