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
“so this difference is confusing and it complicates the learning curve for no real benefit”
Love it :-)
Can we use namespace notation in Symfony 3?
Great move! Thanks.
@Massimiliano you can already use Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction (class name == service id) in Symfony 3.4. But using app.my_controller::myAction instead of app.my_controller:myAction is new in Symfony 4.1