Skip to content
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

Creating a cookbook page for Form Handlers ? #3919

Closed
Einenlum opened this issue Jun 9, 2014 · 6 comments
Closed

Creating a cookbook page for Form Handlers ? #3919

Einenlum opened this issue Jun 9, 2014 · 6 comments

Comments

@Einenlum
Copy link
Contributor

Einenlum commented Jun 9, 2014

Many Symfony2 developers use Form Handlers to handle form submission, but there is no trace of it in the official documentation.

Shouldn't there be a special page about this topic created in the cookbook section? I can do so when I get the opportunity.

@stof
Copy link
Member

stof commented Jun 9, 2014

Many developers are using form handlers because FOSUserBundle 1.x does it this way (we thought it would be a good way to do it at this time). Since then, I changed my mind, and FOSUserBundle 2.x does not have such concept of handlers.

and Symfony2 never had this concept. So IMO, adding a cookbook entry would be a bad idea. I would describe it as the "official" way of handling forms, and I'm not convinced at all it is the best way.

@Nek-
Copy link
Contributor

Nek- commented Jun 9, 2014

There's a big point here. Suggesting a better way to upload files than using doctrine events (we need to remove this piece of doc, seriously :/).

According to you it's better to transform the doctrine-event-based example into a controller-based example ?

@weaverryan
Copy link
Member

Handling uploads is a totally different topic - but yes you're right @Nek- that our cookbook on it is terrible. I've complained a lot about that in #2346 :).

So I'm a big -1 on this too - I don't think form handlers are a good idea. If it's just a little bit of logic, put it in your controller. If it's a lot of logic, then organize it into different services. So, for example, if I needed to send an email after a form submit, I would create a ProductFormHandler::handleSubmit to do that, I would create a ProductMailManager::sendNewProductNotification method instead.

Even for 3rd party bundles, using events is a better idea. Really, I want people to know not to use form handlers - I'm not sure how we can communicate that nicely. Your of course welcome to, but personally, I recommend against this.

Thanks for the conversation anyways! I am interested in making the recommended way of doing things clear :).

@Einenlum
Copy link
Contributor Author

I think you’re right @weaverryan, using services seems a better way to externalize the logic.

Thanks for this interesting discussion :)

@webdevilopers
Copy link

Regarding the short exchange of ideas yesterday on twitter with @weaverryan and @matthiasnoback maybe adding a cookbook page on managers instead would be helpful?

Currently there are examples in the DI chapter:
http://symfony.com/doc/current/components/dependency_injection/parentservices.html

But if it is recommended to handle forms through managers too - not sure about that - this could be added.

Depends on what we define as a manager - is a calculator some kind of service manager too?
http://symfony.com/doc/current/cookbook/testing/database.html

@matthiasnoback
Copy link
Contributor

Frankly, I think that there shouldn't be a cookbook article about this topic. These discussions are about developing software in general, not about working with Symfony. If you have a command/event infrastructure, then having a form handler doesn't make sense at all. The same for managers/services. It all depends, no framework-enforced best practice there. In fact, the good thing about Symfony is that it doesn't push you in one direction with regard to your application's architecture. The Symfony documentation shouldn't tell you anything about this, it's up to you as a software developer (which makes our job a hard one ;)).

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

No branches or pull requests

6 participants