You should get auto-completion in Twig in both cases. Well, actually, the auto-completion seems to be inconsistent in Twig - I only use the simple template name (e.g. genus/show.html.twig) and I get auto-completion *most* of the time, but not always. I'm not sure why it works sometimes, but not other times - I would love to know why! :)
Hi, when i run php app/console container:debug, most of the service id has class Names infront of them, but some of them has not, i.e service_container and request . Why this?
Yea, really good question! First, when a bundle adds a service to the system, it can choose to call it whatever it wants - there are no rules about what a service can be called. So, there is no technical reason for these different names. What you are seeing is am mix between some standards and some "practicality". Basically:
1) If you're creating a re-usable/shareable bundle (this includes the core bundles), it's typical a best practice to somewhat "namespace" your service ids so they don't collide with others. In other words, if I made a KnpCoolGuyBundle, then I might prefix my service ids with knp_coolguy so that they don't collide with service ids from other bundles. This is what you're seeing: service id's are basically being prefixed with a string that's similar to their namespace. But this is just a standard, there's no technical reason for this.
2) On the other hand, nobody likes long names, especially for really commonly-used things. It would be a bummer to have a service called symfony_component_dependency_injection_service_container :). So, sometimes, a bundle will be opinionated and create a service with a very short name for convenience. This is why you have services like doctrine, templating or logger.
8 Comments
I have found another cool trick! I see that you render view like this:
That's okay, but If you change the string indicating the view name you will get autocompletion in twig!
Hey 3amprogrammer!
You should get auto-completion in Twig in both cases. Well, actually, the auto-completion seems to be inconsistent in Twig - I only use the simple template name (e.g. genus/show.html.twig) and I get auto-completion *most* of the time, but not always. I'm not sure why it works sometimes, but not other times - I would love to know why! :)
Cheers!
the "funFact" value does not contain the < p > tag. where does this tag come from?
Hey mehdi!
That's markdown! Well, at least, the markdown parser that we're using wraps all the text in a
<p>tag :).Cheers!
Hi, when i run php app/console container:debug, most of the service id has class Names infront of them, but some of them has not, i.e service_container and request . Why this?
Hey Muhammad!
Yea, really good question! First, when a bundle adds a service to the system, it can choose to call it whatever it wants - there are no rules about what a service can be called. So, there is no technical reason for these different names. What you are seeing is am mix between some standards and some "practicality". Basically:
1) If you're creating a re-usable/shareable bundle (this includes the core bundles), it's typical a best practice to somewhat "namespace" your service ids so they don't collide with others. In other words, if I made a KnpCoolGuyBundle, then I might prefix my service ids with knp_coolguy so that they don't collide with service ids from other bundles. This is what you're seeing: service id's are basically being prefixed with a string that's similar to their namespace. But this is just a standard, there's no technical reason for this.
2) On the other hand, nobody likes long names, especially for really commonly-used things. It would be a bummer to have a service called
symfony_component_dependency_injection_service_container:). So, sometimes, a bundle will be opinionated and create a service with a very short name for convenience. This is why you have services likedoctrine,templatingorlogger.I hope that explains it a bit! Cheers!
You are a great teacher honestly !!! I am very happy to follow all your courses :)
Cheers and thanks! Very happy they are useful!! :)
"Houston: no signs of life"
Start the conversation!