New in Symfony 3.1: FrameworkBundle Improvements
April 20, 2016 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
The FrameworkBundle is the piece that glues all the different Symfony components to create a robust and flexible framework. In Symfony 3.1 we introduced some minor but useful improvements to it.
Deprecated built-in form types as services
If you execute debug:container
command to debug the services defined in the
container of your application, you'll find 29 services related to the built-in
form types:
1 2 3 4 5 6 7
$ ./bin/console debug:container
...
form.type.birthday Symfony\Component\Form\Extension\Core\Type\BirthdayType
form.type.button Symfony\Component\Form\Extension\Core\Type\ButtonType
...
form.type.timezone Symfony\Component\Form\Extension\Core\Type\TimezoneType
form.type.url Symfony\Component\Form\Extension\Core\Type\UrlType
In Symfony 3.1 we've deprecated all these services and they'll be removed in
Symfony 4.0. Instead of using these services, you must use the fully qualified
class name of the form types (e.g. UrlType::class
).
Improved debug:container
and debug:config
commands
In Symfony 3.1, these commands have been improved to help you when no results
are found. First, debug:config
command now displays a Did you mean? list
of suggestions when the bundle name or extension alias is not found.
The debug:container
command already displayed the Did you mean? list of
suggestions, but now, when there is only one suggestion, it displays it
preselected.
Added json()
shortcut to the base controller
The base controller defines shortcut methods for common tasks, such as render()
to render templates and get()
to get container services. In Symfony 3.1 we
added a new shortcut called json()
to turn contents into JSON responses:
1 2 3 4 5 6 7 8 9 10 11
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class ApiController extends Controller
{
public function indexAction()
{
// ...
return $this->json($data);
}
}
If the serializer
service is available, data is serialized with it using the
default encoding options. If not, the regular json_encode()
call is applied
to data.
This shortcut defines three more optional arguments, where the $context
is
the information passed to the serialize()
method (when using the serializer):
1
return $this->json($data, $status = 200, $headers = array(), $context = array());
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
And removing all these form services is good too, I couldn't wait for this removal to happen :D
Nice job for everyone (y)