-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Conversation
templating/embedding_controllers.rst
Outdated
@@ -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**). |
There was a problem hiding this comment.
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.
templating/embedding_controllers.rst
Outdated
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. |
There was a problem hiding this comment.
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
templating/embedding_controllers.rst
Outdated
@@ -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', |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
.
4a38b6a
to
b98cc59
Compare
@weaverryan Hey,Thanks for remarks, updated. |
Thank you @mimol91! |
…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
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