Use form handlers in symfony2
Avoid polluting your controllers with form handling logic by creating a form handler like FooBundle/Form/Handler/RegisterHandler.php
.
Then in your controller:
if ($handler->process($form)) {
// success
} else {
// fail
}
or
$foo = $handler->process($form);
if ($foo === true) {
// success
} else {
// fail - $foo contains something useful (e.g. why it failed)
}
or, set up the service to return a new object each time it is used and:
if ($handler->process($form)) {
// success
} else {
// fail - $handler->getBar(); contains something useful (e.g. why it failed)
}
Written by Kristian Lewis Jones
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#