Skip to content

use handleRequest() instead of bind() #2974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2013
Merged

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Sep 13, 2013

Q A
Doc fix? yes
New docs? no
Applies to 2.3+
Fixed tickets #2969

@xabbuh
Copy link
Member Author

xabbuh commented Sep 13, 2013

#2965 should be merged before this.

@wouterj
Copy link
Member

wouterj commented Sep 13, 2013

-1 for the current state. It's the component docs, we should talk about using the form component without the HttpKernel extension awell as with the HttpKernel extension.

use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;

$formFactory = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should keep the information about the HttpFoundation integration too

@xabbuh
Copy link
Member Author

xabbuh commented Oct 11, 2013

So, if I understand this correctly, you'd pass the superglobals (i.e. $_REQUEST) to handleRequest(), unless you have registered the HttpFoundationExtension?

@stof
Copy link
Member

stof commented Oct 11, 2013

@xabbuh No, when using the NativeRequestHandler, you call it without argument (or with null as argument)

@xabbuh
Copy link
Member Author

xabbuh commented Oct 11, 2013

Thanks for the clarification. Think I got it. But, where is the advantage on using the HttpFoundationExtension. For me, calling $form->handleRequest() seems to be simpler than calling $form->handleRequest($request).

@stof
Copy link
Member

stof commented Oct 11, 2013

@xabbuh see the chapter of the doc describing the advantages of HttpFoundation or http://blog.servergrove.com/2013/09/23/symfony2-components-overview-httpfoundation/ for instance.
$form->handleRequest() looks simpler at first, until you start testing your code (it uses super globals, so it relies on a global state and your code will not be testable anymore with the BrowserKit shipped by HttpKernel directly).
If your application uses the HttpFoundation component, you should be using its integration so that your form operates on the same data than the app (it would be confusing if you use a listener to modify the legacy input of your app to the new format and the form does not use the processed input when binding for instance).

@xabbuh
Copy link
Member Author

xabbuh commented Oct 12, 2013

That makes sense. Should have thought of. Would it be useful to add your explanation to this section?

weaverryan added a commit that referenced this pull request Dec 17, 2013
Added some additional details about what's going on behind the scenes
@weaverryan weaverryan merged commit a5c4a4f into symfony:2.3 Dec 17, 2013
@weaverryan
Copy link
Member

Thanks Christian! I've merged this and added a few more details about what's going on behind the scenes with the handlers (sha: 1beb526). If you see any issues, let me know or make a PR of course :).

Cheers!

@xabbuh xabbuh deleted the issue-2969 branch December 17, 2013 22:22
weaverryan added a commit that referenced this pull request Dec 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants