New in Symfony 4.1: Deprecated the bundle notation

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Contributed by
Tobias Schultze
in #26085.
In modern Symfony applications, it's no longer recommended to organize your business logic using bundles. However, it was still possible to use the "bundle notation" for example when defining routes:
1 2 3 4
bundle_controller:
path: /
defaults:
_controller: FrameworkBundle:Redirect:redirect
In order to keep simplifying things and to keep replacing "Symfony concepts" by standard PHP features, in Symfony 4.1 we've deprecated the bundle notation in favor of the regular PHP namespace notation:
1 2 3 4
bundle_controller:
path: /
defaults:
_controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
While working on this, we noticed a related inconsistency that could be fixed.
When defining controllers as services, you must use a single colon (:
)
instead of a double colon (::
) to separate the service ID and the method name:
1 2 3 4
service_controller:
path: /
defaults:
_controller: app.my_controller:myAction
In other parts of Symfony you always use a double colon (::
) to separate
classes and method names, so this difference is confusing and it complicates the
learning curve for no real benefit. That's why in Symfony 4.1 you can always use
a double colon to separate the method names, even for controllers as services:
1 2 3 4
service_controller:
path: /
defaults:
_controller: app.my_controller::myAction
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
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Love it :-)