Closed
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | yes |
Symfony version | 4.1 |
In this page: https://symfony.com/doc/current/controller/service.html we explain an alternative syntax to use controllers-as-services in route definitions:
hello:
path: /hello
defaults: { _controller: app.hello_controller:indexAction }
My concern is the note below that example:
You cannot drop the Action part of the method name when using
the single colon notation.
If this is still true, isn't it a bit arbitrary? Could we make the Action
suffix optional?
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
yceruto commentedon Nov 15, 2017
IIRC it isn't optional, but it should match the name of the method, so you should/can remove the
Action
suffix safely if the method name doesn't have this suffix.chalasr commentedon Nov 15, 2017
Seems like the doc is wrong indeed, using
app.hello_controller:index
works fine from 2.7 to 3.4.javiereguiluz commentedon Nov 15, 2017
Closing then as a doc issue. Thanks!
chalasr commentedon Nov 15, 2017
Wait, I believe that what the doc tries to point out is that when using the
a:b:c
notation e.g.App:Default:index
, it's resolved asAppBundle\Controller\DefaultController::indexAction()
. But when using the single colon notation theAction
suffix is not automatically added, which is still true.javiereguiluz commentedon Nov 15, 2017
@chalasr beware that this is tricky. The note says: "when using this, you must call your controller methods xxxAction() you cannot remove 'Action' suffix".
A different thing is that if you called your action
index
you must use... : index
and if you called itindexAction
you muse use... : indexAction
So, the question: must controller methods be called
...Action()
or is...()
OK too?minor #8669 Removed a wrong note about controllers as services (javie…