Chapters
21 Chapters
|
2:23:48
|
Login to bookmark this video
-
Course Code
Login or register to download the code!
Login or register to download the code!
-
This Video
Login or register to download the video!
Login or register to download the video!
-
Subtitles
Login or register to download the subtitles!
Login or register to download the subtitles!
-
Course Script
Login or register to download the script!
Login or register to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/asset": "6.0.*", // v6.0.3
"symfony/console": "6.0.*", // v6.0.3
"symfony/dotenv": "6.0.*", // v6.0.3
"symfony/flex": "^2", // v2.4.5
"symfony/framework-bundle": "6.0.*", // v6.0.4
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/runtime": "6.4.3", // v6.4.3
"symfony/twig-bundle": "6.0.*", // v6.0.3
"symfony/ux-turbo": "^2.0", // v2.0.1
"symfony/webpack-encore-bundle": "^1.13", // v1.13.2
"symfony/yaml": "6.0.*", // v6.0.3
"twig/extra-bundle": "^2.12|^3.0", // v3.3.8
"twig/twig": "^2.12|^3.0" // v3.3.8
},
"require-dev": {
"symfony/debug-bundle": "6.0.*", // v6.0.3
"symfony/stopwatch": "6.0.*", // v6.0.3
"symfony/web-profiler-bundle": "6.0.*" // v6.0.3
}
}
20 Comments
After following steps my homepage wont load
Hey Frank,
Did you try to follow the advice in the error message, i.e. running
composer require symfony/twig-bundle? It might be a good idea to try to remove that bundle and install again, probably it was not installed well. Keep the eye on any prompts in the console - you may need to allow some Flex recipe execution to let Symfony set up everything for you :)Cheers!
I have a problem with twig, seemingly, specifically with device viewport. I have installed webpack Encore.
I am testing some symfony code on mobile devices, and I add some code that returns the viewport width.
When I compute the raw code for my web page into the variable
$htmland my controller returnsnew Response($html), I check that the viewport of my iPhone is 393px, which is normal. On my tablet, the viewport is 744px, which is also normal.When I use twig, the twig body simply returns the window width, computed the same way as previously. I do not even input extra code. Then I get a viewport of 980px both on my iPhone and on my tablet.
I have tested this on my local ntework and also from a remote server. I use actual devices for all my tests.
This has very serious consequences when it comes to responsive design. actually, I have done all of these tests because I could not set my font sizes correctly on my phone and tablet when testing my symfony app.
All of this has been done on a fresh install of Symfony+Encore.
Can you help me?
Tia,
François
I got the answer.
The default base.html.twig file does not have the viewport meta tag in the head.
Ah, thanks for following up that you found that!
Hey, could I ask, how did you implement the changes for each string in the list when adding a song and an artist attribute?
Hey Ivangogh,
Ryan cheated a little bit by copy-pasting the new array, but he converted a simple array with many string items inside into an array of arrays where each item is an array containing two keys, song, and artist.
Cheers!
Hi
We are upgrading from SF5.4 to SF6.0 and we get this error when visiting any page:
You cannot use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".
We already have that bundle installed, looking to the renderView method, it seems like "twig" service is not being injected to the Controller.
Injecting Environment $twig to constructor of the controller works ( new Response($this->twig->render(...))) but this limitates us, because can not use the shortcuts provided by AbstractController and would have to refactor a lot of code.
Any idea? help on this would be very appreciated :). Thanks a lot.
Hey Samuel,
That's unexpected :) - Do you have the autoconfigure and autowire features enabled? If that's the case, try injecting the Twig service into any service class. My guess is the Twig service is being removed from the container because nothing is using it
Cheers!
Hi MolloKhan,
First of all thank you very much for your quick response.
Yep, really unexpected :/
The same project downgraded to SF5.4 works fine, but fails when changed the version to SF6.1 in composer at this point.
We have some services with twig injected, so no idea why fails at this point:
Hi,
We finnaly found the issue in services.yaml
We had to change the bind parameter => $container: '@service_container'
To the service alias => Symfony\Component\DependencyInjection\ContainerInterface: '@service_container'
We have an auto authentication functionallity in our Behat Context tests, so we needed the $container to be bind for ease of configuration.
Replacing the bind by the alias fixed the issue.
Thank you for your help.
Regards!
Ohh, so the
containerservice injected into your controllers was been modified due to your binding config, that's interesting!I'm glad to know you solved your problem. Cheers!
Upon extending the AbstractController class, the following exception is occurring:
"Controller\VinylController" has no container set, did you forget to define it as a service subscriber?I tried clearing up the caches with
bin/console cache:clear, even stopped the server and restarting it, but the exception is still showing up. What's the solution to this annoying problem, as I cannot proceed further with the tutorial?Thank you.
Hey @roenfeldt!
Ah, sorry about the trouble - that's super weird! Hmm. So, the reason why this made happen is a bit technical... your controllers should be (via
config/services.yaml) auto-registered as services and autoconfigured (but things we talk about in the next tutorial). It seems that one of those two things isn't happening... but I can't imagine why. Have you modified yourservices.yamlfile at all? What is the namespace insideVinylController? It should benamespace App\Controller- based on the error, are you missing theApp\part at the beginning?Let me know if any of this helps :). This is basically an error that shouldn't be happening - so there is likely some small typo (and a non-friendly error for the typo) or something else weird happened.
Cheers!
Hello Ryan,
Thank you for the very fast reply, as well as for the solution provided. It was, as you correctly suspected, the namespace which was missing the
App\part for some reason. In any case, now everything's working as it should.Amazing level of support, I am definitely going to become a paid subscriber at SymfonyCasts very soon :)
Six stars out of five!
Yay! Cheers and keep up the good work ❤️
Typo suggestion: common to have a directory with the same
knowname as your controller class (can't edit it on github for some reason atm)Hey Mark!
Thank you for reporting this! I fixed it in https://github.com/SymfonyC...
Cheers!
"Houston: no signs of life"
Start the conversation!