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

Warn on issue with controllers-as-services versus @Route annotation #6258

Closed
wants to merge 1 commit into from
Closed

Warn on issue with controllers-as-services versus @Route annotation #6258

wants to merge 1 commit into from

Conversation

DHager
Copy link
Contributor

@DHager DHager commented Feb 10, 2016

I just ran into this problem and it took me a while. Without the @Route(service="myid") annotation, the controller was always being instantiated without any arguments, completely ignoring my service-definition.

Not sure how far back/forward this applies to other versions.

@DHager DHager changed the title Warn that annotated controllers may be instantiated wrongly Warn on issue with controllers-as-services versus @Route annotation Feb 10, 2016
@@ -76,6 +76,13 @@ Then you can define it as a service as follows:
'AppBundle\Controller\HelloController'
));

.. caution::

If you are managing your routes with PHP annotation, you may need to add an
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a may. It is always needed (otherwise the controller is not used as a service)

@wouterj
Copy link
Member

wouterj commented Jul 8, 2016

Hi @DHager. Thanks for this little caution, I think it makes sense. I've applied @stof's suggestions and merged the caution with a tip below in #6734. I've included your commit in that PR, so you'll still get the credits.

@wouterj wouterj closed this Jul 8, 2016
wouterj added a commit that referenced this pull request Jul 9, 2016
…n (DHager, WouterJ)

This PR was merged into the 2.7 branch.

Discussion
----------

Add little caution to add service id for @route annotation

Finishes #6258

Original PR description:

 > I just ran into this problem and it took me a while. Without the `@Route(service="myid")` annotation, the controller was *always* being instantiated without any arguments, completely ignoring my service-definition.

 > Not sure how far back/forward this applies to other versions.

Commits
-------

93bb21c Merge caution with annotations tip
ac6b008 Add warning about a pitfall where the controller seems to be instantiated without using the service-definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants