Skip to content

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

Closed
@javiereguiluz

Description

@javiereguiluz
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?

Activity

added
RFCRFC = Request For Comments (proposals about features that you want to be discussed)
DXDX = Developer eXperience (anything that improves the experience of using Symfony)
on Nov 15, 2017
yceruto

yceruto commented on Nov 15, 2017

@yceruto
Member

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

chalasr commented on Nov 15, 2017

@chalasr
Member

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

javiereguiluz

javiereguiluz commented on Nov 15, 2017

@javiereguiluz
MemberAuthor

Closing then as a doc issue. Thanks!

chalasr

chalasr commented on Nov 15, 2017

@chalasr
Member

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

javiereguiluz commented on Nov 15, 2017

@javiereguiluz
MemberAuthor

@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?

added a commit that references this issue on Nov 16, 2017

minor #8669 Removed a wrong note about controllers as services (javie…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)FeatureRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @javiereguiluz@yceruto@chalasr

        Issue actions

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