Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Make the 'Action' suffix optional in controllers-as-services #24976

Closed
javiereguiluz opened this issue Nov 15, 2017 · 5 comments
Closed
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@javiereguiluz
Copy link
Member

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?

@javiereguiluz javiereguiluz added Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) DX DX = Developer eXperience (anything that improves the experience of using Symfony) labels Nov 15, 2017
@yceruto
Copy link
Member

yceruto commented 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
Copy link
Member

chalasr commented Nov 15, 2017

Seems like the doc is wrong indeed, using app.hello_controller:index works fine from 2.7 to 3.4.

@javiereguiluz
Copy link
Member Author

Closing then as a doc issue. Thanks!

@chalasr
Copy link
Member

chalasr commented 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 as AppBundle\Controller\DefaultController::indexAction(). But when using the single colon notation the Action suffix is not automatically added, which is still true.

@javiereguiluz
Copy link
Member Author

javiereguiluz commented 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 it indexAction you muse use ... : indexAction

So, the question: must controller methods be called ...Action() or is ...() OK too?

xabbuh added a commit to symfony/symfony-docs that referenced this issue Nov 16, 2017
…reguiluz)

This PR was squashed before being merged into the 2.7 branch (closes #8669).

Discussion
----------

Removed a wrong note about controllers as services

This is probably wrong. We're discussing about that in symfony/symfony#24976.

Commits
-------

669a9f0 Removed a wrong note about controllers as services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

3 participants