I am getting started with Symfony2 and I am trying to understand the Form Component. I am looking at this page http://docs.symfony-reloaded.org/guides/forms/overview.html
And I can understand how we create form classes but what is confusing is how we actually use those forms in our controller.
$form = ContactForm::create($this->get('form.context'));
Does anyone have a more in depth explanation of the form.context portion of this code, and the actual process behind using forms within controllers?
Thanks.
form.contextservice is aSymfony\Component\Form\FormContextobject by default. Here’s a full definition of this service:Actually it’s a very simple object that just prepare some basic options used by almost every form, ie. a validator, CSRF protection and field factory.
In fact the code you’ve posted is equivalent of: