Skip to content

Update controller syntax for bundle-less applications #8555

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

Merged
merged 1 commit into from
Nov 5, 2017

Conversation

mimol91
Copy link
Contributor

@mimol91 mimol91 commented Oct 28, 2017

Update information how to render controller action in bundle-less applications.
Symfony 4 encourages to do not use bundles, thus why embedding controller action in twig is slightly different.
App\\Controller\\ArticleController:recentArticles instead of 'bundle syntax' AppBundle:Article:recentArticles

@@ -67,8 +67,9 @@ The ``recent_list`` template is perfectly straightforward:
(e.g. ``/article/*slug*``). This is a bad practice. In the next section,
you'll learn how to do this correctly.

To include the controller, you'll need to refer to it using the standard
string syntax for controllers (i.e. **bundle**:**controller**:**action**):
To include the controller, you'll need to refer to it using the standard string syntax for controllers (i.e. **controllerPath**:**action**).
Copy link
Member

Choose a reason for hiding this comment

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

Actually, I believe we should use the :: syntax. A single colon requires the controller to be a service. But if you use ::, then Symfony looks in the container first to see if it is a service, but then falls back to instantiating the controller. So, it's a bit more universal.

string syntax for controllers (i.e. **bundle**:**controller**:**action**):
To include the controller, you'll need to refer to it using the standard string syntax for controllers (i.e. **controllerPath**:**action**).

Where controllerPath is a Full Qualified Class Name. (Notice double ``\\`` as a directory separator) and action is method in controller without the action postfix.
Copy link
Member

Choose a reason for hiding this comment

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

I think you can remove this entirely, as the examples below illustrate this nicely

@@ -79,7 +80,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):
{# ... #}
<div id="sidebar">
{{ render(controller(
'AppBundle:Article:recentArticles',
'App\\Controller\\ArticleController:recentArticles',
Copy link
Member

Choose a reason for hiding this comment

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

Are the double-slashes needed? I'm really not sure - that's why I'm asking :)

Copy link
Member

Choose a reason for hiding this comment

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

Twig auto-escapes the \ character so by the time it makes it to the controller function PHP code, the namespace looks like AppControllerArticleController. By double escaping it, you're forcing the correct namespace to make it through App\Controller\ArticleController.

@mimol91
Copy link
Contributor Author

mimol91 commented Nov 3, 2017

@weaverryan Hey,Thanks for remarks, updated.

@weaverryan
Copy link
Member

Thank you @mimol91!

@weaverryan weaverryan merged commit 480c1a6 into symfony:master Nov 5, 2017
weaverryan added a commit that referenced this pull request Nov 5, 2017
…mol91)

This PR was merged into the master branch.

Discussion
----------

Update controller syntax for bundle-less applications

Update information how to render controller action in bundle-less applications.
Symfony 4 encourages to do not use bundles, thus why embedding controller action in twig is slightly different.
`App\\Controller\\ArticleController:recentArticles`  instead of 'bundle syntax' `AppBundle:Article:recentArticles`

Commits
-------

480c1a6 Update controller syntax for bundle-less applications
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