Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Events, Events & Events!

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Hi friends! Ok: so you already know how to use Symfony... maybe you... use it every day. Heck, I love it so much, I've been known to use it on vacation! And now, you're ready to go deeper - to find out how Symfony really works under-the-hood. If this is you, welcome! We're in for a wild ride.

In this first deep dive tutorial, we're going to the heart of what happens during the request-response process in Symfony. It all centers around a class called HttpKernel, which is an incredible class. This one class is used as the heart of Symfony and Drupal... as well as a bunch of other projects, for example, phpBB - the famous forum system.

So how can one class be the heart of technologies that are seemingly so different? That's what we're going to find out.

Project Setup

As always, if you truly want to impress your friends with your deep knowledge of Symfony, download the course code and code along with me. After you unzip the file, you'll find a start/ directory with the same code that you see here. Follow the README.md file for all the thrilling setup instructions.

The last step will be to leverage the Symfony binary to start a web server with symfony serve. I'm actually going to pass -d so it runs in the background as a daemon:

symfony serve -d

Now, spin back over to your browser and head to https://localhost:8000 to find: The SpaceBar. Some of you might recognize this from our Symfony 4 tutorials. Well, I've upgraded it to Symfony 5 and it will be our perfect guinea pig for diving deep into Symfony.

Request -> Controller -> Response. But what else?

Ok: we know that everything starts with a request: a request comes into our server, it's handled by our application, yadda, yadda, yadda, a response comes out... and profit! The goal of this tutorial is simple: find out what really happens in between.

For the homepage, let's find its controller: src/Controller/ArticleController.php. Here it is: homepage(), with the route above it.

The two things that we know happen between the start of the request and the end of the response, are that the route is matched and then something calls our controller... probably Fabien personally calls it... I don't know. And then our controller always, well usually, returns a response. That's what $this->render() returns.

What I want to know is: who executes the routing and who ultimately calls my controller? I want to see the code that does that!

Holder of Secrets: The Profiler Performance Tab

To start this journey, go back to your browser and, on the web debug toolbar on the bottom, right click on the milliseconds link and open it in a new tab to jump into the "Performance" section of the profiler.

This screen is awesome. It's meant to show you where your site might be slow, but its real superpower is that it can show you everything that's happening inside of Symfony. The trick is to change this "threshold" input box from 1 milliseconds down to 0... so that it doesn't hide anything.

Simply gorgeous. This is the request-response process. You can see - kind of in the middle here - is our controller: it took 36 milliseconds to execute. You can see the Twig templates being executed below it, and even little Doctrine queries happening along the way.

The biggest thing I want you to notice is that most of the other lines - both before and after the controller - contain the word Listener, or sometimes Subscriber, which is basically another word for "listener".

Because, at a high level, here's what happens inside Symfony: it boots, triggers some events, executes your controller, then dispatches some other events.

To get an even better view of these events, click... the Events tab! This shows all the events that were dispatched during this request. So, apparently there's an event called kernel.request: that was the first event dispatched. And here are all of the listeners - so all the "functions" - that were called when that event was triggered.

Then there's another event called kernel.controller... and many more. You can even see listeners for events that were not triggered during this request.

So... let's start messing with stuff! Next, let's create our own event listener and execute code before our controller is called.

Leave a comment!

49
Login or Register to join the conversation
Danijel A. Avatar
Danijel A. Avatar Danijel A. | posted 2 years ago

I tried setting up the project by readme file, but as soon as I try to run composer install, this error pops up in the terminal:

composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for lorenzo/pinky 1.0.5 -> satisfiable by lorenzo/pinky[1.0.5].
- lorenzo/pinky 1.0.5 requires ext-xsl * -> the requested PHP extension xsl is missing from your system.
Problem 2
- lorenzo/pinky 1.0.5 requires ext-xsl * -> the requested PHP extension xsl is missing from your system.
- twig/inky-extra v2.12.5 requires lorenzo/pinky ^1.0.5 -> satisfiable by lorenzo/pinky[1.0.5].
- Installation request for twig/inky-extra v2.12.5 -> satisfiable by twig/inky-extra[v2.12.5].

To enable extensions, verify that they are enabled in your .ini files:
- C:\xampp\php\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

EDIT: the problem has been fixed, I needed to enable xsl in php.ini file

3 Reply

[Important] hello symfonycast, please i have a really big problem trying to setting up the symfony 4 project in my machin, it would be a really great help if there's any place where i can share my screen and help me to figure this out, i tryed all the commands and searched in the internet, i tryed to update my composer as well to enable init file in php but nothing works, i'm goin in a trip this week and i'm trying to fix this so i can follow the course while i'm traveling (i downloaded the videos ) if you have instagram or discord it will be veeery appreciated thank you <3

1 Reply

Hey Soufiyane

I'm afraid we do not offer that service (we just don't have enough bandwith do have a 1:1 call with everyone). Could you give me more context and explain your problem so I can understand what's going on an help you out

Cheers!

Reply

8 houres and still no luck to fix it :((

Reply

I have to confess that I had a really hard time setting up this project :(

1) You used to have a docker-compose file in the project to set up the database. That was quite handy. I started with postgres just to find out that mysql is required when running the migrations...
2) I think there is a problem running mysql migrations in PHP 8. It just fails with a message saying that "There is no active transaction". The fix is to manually edit every migration and add a


public function isTransactional(): bool {
return false;
}


to it...
3) Finally I hit an error I had never seen before... Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DoctrineParamConverter::__construct(): Argument #1 ($registry) must be of type ?Doctrine\Common\Persistence\ManagerRegistry, Doctrine\Bundle\DoctrineBundle\Registry given
Seems like just another B/C break in doctrine that is fixed in a framework-bundle update so... I just ran composer update and... welcome to the space bar :)

Not sure if I have done something wrong or it was just some B/C breaks with doctrine and PHP8...
Maybe you should fix the PHP version to 7.4 in composer.json, create a .php-version file and make more use of the symfony binary to select the "correct" PHP version?

1 Reply

Hey @Kuku!

Thanks for posting - this is 100% my fault! Last week, on a few of our tutorials, I did some minor dependency upgrades to add PHP 8 support. However, I ended up with 2 bad version combinations that I didn't realize! And you hit both issues!

> 1) You used to have a docker-compose file in the project to set up the database. That was quite handy. I started with postgres just to find out that mysql is required when running the migrations...

We do have a docker-compose file on some projects, but not on this one... it was just before we started doing it. But... that's perhaps something we should always include. it *is*, indeed handy. That's also a good point about the migrations - we should just document using doctrine:schema:update --force in the README. There is no advantage in a tutorial project to using the migrations :).

> I think there is a problem running mysql migrations in PHP 8. It just fails with a message saying that "There is no active transaction".

If you're using PHP 8 and MySQL, you get this. In that case, you need to composer up doctrine/migrations (it was a bug they fixed just 8 days ago).

> Finally I hit an error I had never seen before... Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DoctrineParamConverter::__construct(): Argument #...

This is a bad version combo I created between SensioFrameworkExtraBundle and Doctrine. The fix there is to run compose up sensio/framework-extra-bundle.

Anyways, sorry about the trouble! I'm going to get the code downloads fixed up ASAP!

Cheers!

Reply
gazzatav Avatar
gazzatav Avatar gazzatav | posted 3 months ago

Feel like I've been a bit busy on the comments today but here goes another one! The events page on the profiler shows my subscriber in the not called section. I've even given it a high priority and it makes no difference it is simply not called. It shows up when I use this command:

symfony console debug:event-dispatcher request

Registered Listeners Grouped by Event
=====================================
"App\EventSubscriber\RequestEvent" event
----------------------------------------
------- ------------------------------------------------------------ ----------
Order Callable Priority
------- ------------------------------------------------------------ ----------
#1 App\EventSubscriber\UserAgentSubscriber::onKernelRequest() 2048
------- ------------------------------------------------------------ ----------

Given that it is a subscriber and autowired, there does not seem to be any possibility of configuring it. In the profiler for that event, 41 were called, 37 were not called and 7 were orphaned. As I put the priority up to 2048 I expected it to be called before most of the others. How do you get a subscriber to always work?

Reply
gazzatav Avatar
gazzatav Avatar gazzatav | posted 3 months ago | edited

@there , I'm getting there, just configured some variables in services (probably with the wrong values) and the page is back but the bottom left section is missing and it seems to be something to do with the javascript:

bootstrap:89 Uncaught TypeError: Cannot read properties of undefined (reading 'call')
at __webpack_require__ (bootstrap:89:1)
at ./node_modules/core-js/modules/es.function.name.js (es.function.name.js:2:28)
at __webpack_require__ (bootstrap:89:1)
at ./assets/js/app.js (app.js:25:93)
at __webpack_require__ (bootstrap:89:1)
at checkDeferredModules (bootstrap:45:1)
at Array.webpackJsonpCallback [as push] (bootstrap:32:1)
at app.js:1:57
:8001/favicon.ico:1 Failed to load resource: the server responded with a status of 404 ()

Reply

Hey Gary,

Let me clarify some things... Did you download the course code and started from start/ dir? Did you follow the instructions in the README of that start/ dir? Did you have any errors during executing those commands in your console? You might be missing something, but it's difficult to say what exactly.

Cheers!

Reply
gazzatav Avatar

Hi Victor,
Yes, for this I used the start files. I have php8.1 installed now and some of those libraries simply don't support it. One big problem was that I didn't know that I had to keep adding libraries with higher versions to the composer require command line until all the problems were resolved. I spent a long time going round in circles trying to find the key library to update to make all the others work. The '--with-all-dependencies' option that composer suggests doesn't do what it sounds like. I didn't realise at first that you need to manually work out the new versions and re-require everything at once to complete the dependency chain. After putting ten or so new requirements at a time things started to progress. The help is classic:

--update-with-all-dependencies Allows all inherited dependencies to be updated, including those that are root requirements.

I used this a lot and it did nothing. Just told me there were problems. I suspect the root requirements part of the explanation means 'If and only if the version constraint (or lock file) allows it' - which is exactly what you don't want when you want it to break out of the ceiling and fix everything. Anyway, sounds like a bit of a rant but I'll leave it here in case it helps anyone else.

Cheers!

Reply

Hey Gary,

Hm, this course should support PHP 8.1, so if you have any specific package that you cannot install following this course - let us know in the comments below the video.

Yeah, good tip about that "--update-with-all-dependencies" - it might be useful indeed. Well, ideally you should not upgrade the course because everything should work out of the box, I see this course code should work on PHP 8.1, and so technically you just need to run composer install in the beginning and then just use "composer require" commands to add more packages, the only think you need is to specify a specific (lower) version if composer cannot resolve the deps itself. But if you decide to go a different way and upgrade the tutorial's code to the latest dependencies - yes, you might discover some problems after it that you would need to fix manually.

So, for learning purposes, we do recommend to run "composer install" instead of "composer update" for simplicity, but that's up to you :)

Cheers!

Reply
gazzatav Avatar

Hi Victor
"should support PHP 8.1"
I don't know if this means what I think it means (I see 'doctrine' and I think 'that'll be important') but vendor/doctrine/dbal/composer.json has this in the start folder straight after composer install:

"bin": ["bin/doctrine-dbal"],
"config": {
"sort-packages": true,
"platform": {
"php": "7.3.0"

I used composer install from the get-go but straight away found there was no migration:list command, that is a command I have used extensively in other tutorials and would not want to be without - especially to set up the new default dbms, Postgresql - doctrine doesn't fully support a dsn string in .env yet (try using a socket) :)
Cheers

Reply

Hey Gary,

Ah, it might be so, yes. I mean, we do not constrain the PHP version in our composer.json, but it seems like a thord-party dependency like Doctrine you mentioned does this. Yeah, it sounds like you have to upgrade the Doctrine then. But did you get an error about it during the "composer install" in the start/ directory of the downloaded course code? Because I just downloaded the course code and was able to run "composer install" on the locked version of this file without any errors.

Cheers!

Reply
gazzatav Avatar
gazzatav Avatar gazzatav | posted 3 months ago | edited

Hi @there , Lol, I just did a recursive diff of the start and finish course files and there's not much difference! I was alerted to this when trying to solve a problem about Symfony\Component\Asset\Context\RequestStackContext not being autowired. Searching online I found the answer in another tutorial 'Symfony Uploading' Chapter 10. So then I thought 'How can that be missing in the start tutorial, it should already be configured because it's needed in UploadHelper.php'. When folks have problems like all the ones in this Chapter 1 discussion, do you check it on a fresh download from the site?

Currently dealing with:
Cannot autowire service "App\Service\UploaderHelper": argument "$uploadedAssetsBaseUrl" of method "__construct()" is type-hinted "string", you should configure its value explicitly.

Diff:

→ diff -r start/ finish/
diff -r start/config/routes.yaml finish/config/routes.yaml
1,3c1,6
< #index:
< # path: /
< # controller: App\Controller\DefaultController::index
---
> index:
> path: /playing/{id}
> defaults:
> _controller: App\Controller\DefaultController::index
> id: 10
> totally_inventing_this_default: true
diff -r start/src/Controller/ArticleController.php finish/src/Controller/ArticleController.php
9a10,11
> use Symfony\Component\HttpFoundation\Request;
> use Symfony\Component\HttpKernel\HttpKernelInterface;
19a22
> private $logger;
21c24
< public function __construct(bool $isDebug)
---
> public function __construct(bool $isDebug, LoggerInterface $logger)
23a27,29
> $this->logger = $logger;
>
> $this->logger->info('Controller instantiated!');
29c35
< public function homepage(ArticleRepository $repository)
---
> public function homepage(ArticleRepository $repository, LoggerInterface $logger, $isMac, HttpKernelInterface $httpKernel)
30a37
> $logger->info('Inside the controller!');
32a40,52
> /*
> // manual sub-request example
> $request = new Request();
> $request->attributes->set('_controller', 'App\\Controller\\PartialController::trendingQuotes');
> $request->server->set('REMOTE_ADDR', '127.0.0.1');
>
> $response = $httpKernel->handle(
> $request,
> HttpKernelInterface::SUB_REQUEST
> );
> dump($response);
> */
>
34a55
> 'isMac' => $isMac,
41c62
< public function show(Article $article, SlackClient $slack)
---
> public function show(Article $article, SlackClient $slack, ArticleRepository $articleRepository, $isMac)
42a64,65
> dump($isMac);
>
Only in finish/src/Controller: PartialController.php
Only in finish/src/EventListener: UserAgentSubscriber.php
Only in finish/src/Service: IsMacArgumentValueResolver.php
diff -r start/templates/article/homepage.html.twig finish/templates/article/homepage.html.twig
51,57d50
< </div>
<
< <div class="quote-space pb-2 pt-2">
< <h3 class="text-center pb-3">Trending Quotes</h3>
<
< <div class="px-5">
<

"Our two greatest problems are gravity and paperwork. We can lick gravity, but sometimes the paperwork is overwhelming."
Wernher von Braun, Rocket Engineer


59,62c52,55
<

"Let's face it, space is a risky business. I always considered every launch a barely controlled explosion."
Aaron Cohen, NASA Administrator


<
<

"If offered a seat on a rocket ship, don't ask what seat. Just get on."
Christa McAuliffe, Challenger Astronaut


< </div>
---
> {% if isMac %}
> <hr>
> <small>BTW, you're using a Mac!</small>
> {% endif %}
63a57,60
>
> {{ render(controller('App\\Controller\\PartialController::trendingQuotes', {
> _isMac: isMac
> })) }}
Only in finish/templates: partial

Reply
gazzatav Avatar
gazzatav Avatar gazzatav | posted 3 months ago | edited

Hi @there , wow, I've been trying to get out of dependency hell for several days now. I'm getting quite good at reading the error messages from composer after a failed require! For me this is a really important tutorial to do. After upgrading php from 7.2 to php 8.1 to be able to do previous tutorials I find that a lot of the libraries for this project have not been upgraded to support later versions of php or even each other. Flysystem has changed its api as well.

I did have the space bar working albeit a little broken at one point (had to change the migrations path, configure the dsn for postgres - string in env doesn't work for sockets). Then I noticed that a lot of console commands that I had become accustomed to were not available so I started on the upgrade path - and I'm only talking about upgrading to major symfony libraries at ^5.3|^5.4 ish.

Currently I cannot even clear the cache because there is no FilesystemInterface available for the App\Service\UploaderHelper. I cannot even find a library that supports that interface. How do you find a class in a package if you don't know the package? If I search for filesysteminterface on packagist it gets one result 'liip/imagine-bundle' but that is the library that uses the interface, it doesn't provide it. Will you be revisiting this tutorial in the near future? Personally I'm not bothered about a docker set up but maybe you could give a minimum set up (like which libraries to substitute and required config) to get started and I'll figure the rest out as I go. Or, how can I hack the UploaderHelper to work with a recent Flysystem library? I list my current, almost working requires below.

Cheers

require:
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"antishov/doctrine-extensions-bundle": "^1.4",
"aws/aws-sdk-php": "^3.87",
"composer/package-versions-deprecated": "^1.11",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.12",
"easycorp/easy-log-handler": "^1.0",
"http-interop/http-factory-guzzle": "^1.0",
"knplabs/knp-markdown-bundle": "^1.9",
"knplabs/knp-paginator-bundle": "^5.0",
"knplabs/knp-snappy-bundle": "^1.4.1",
"knplabs/knp-time-bundle": "^1.19",
"league/flysystem-aws-s3-v3": "^1.0",
"league/html-to-markdown": "^4.8",
"liip/imagine-bundle": "^2.1",
"php-http/guzzle7-adapter": "^1.0",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^6.2",
"symfony/asset": "5.4.*",
"symfony/cache": "5.4.*",
"symfony/config": "5.4.*",
"symfony/console": "5.4.*",
"symfony/dependency-injection": "5.4.*",
"symfony/doctrine-bridge": "^5.2.7",
"symfony/dotenv": "5.4.*",
"symfony/flex": "^2",
"symfony/form": "5.4.*",
"symfony/framework-bundle": "5.4.*",
"symfony/http-foundation": "5.4.*",
"symfony/http-kernel": "5.4.*",
"symfony/mailer": "5.4.*",
"symfony/messenger": "5.4.*",
"symfony/mime": "5.4.*",
"symfony/monolog-bundle": "^3.0",
"symfony/property-access": "5.4.*",
"symfony/property-info": "5.4.*",
"symfony/routing": "5.4.*",
"symfony/security-bundle": "^5.4.0",
"symfony/security-core": "^5.4",
"symfony/security-csrf": "^5.4",
"symfony/security-guard": "^5.4",
"symfony/security-http": "^5.3",
"symfony/sendgrid-mailer": "5.4.*",
"symfony/serializer": "5.4.*",
"symfony/translation": "^5.4",
"symfony/twig-bridge": "^5.3",
"symfony/twig-bundle": "5.4.*",
"symfony/validator": "5.4.*",
"symfony/webpack-encore-bundle": "^1.14",
"symfony/yaml": "5.4.*",
"twig/cssinliner-extra": "^2.12",
"twig/extensions": "^1.5",
"twig/extra-bundle": "^2.12|^3.0",
"twig/inky-extra": "^2.12",
"twig/twig": "^2.12|^3.0"

Reply

Hey Gary,

I suppose you kinda solved this according to your another comment above: https://symfonycasts.com/sc... , right?

Or is this question still relevant to you?

Cheers!

Reply
gazzatav Avatar

You're right! But thanks for replying.

If I get this all fixed up for Symfony 5.4, would it be something you'd be interested in having back or is 5.4 all 'old hat' now?

I'm trying to get the images working properly and find replacements for deprecated cache adapters which I know nothing about and for which the documentation seems to run out just at the point where you don't quite understand what's supposed to be changed. It would be nice if people upgrading would show the difference in terms of 'It used to be like that but now it's like this'. Most of the documentation I can find on this subject is in a form which serves to remind an expert what to do. It looks bright and shiny but it doesn't go far enough and it's specific to each part where it needs to be holistic.

As an exercise I'm also working on integrating zenstruck/foundry and upgrading the security as that all changed in 5.3.

Currently the javascript seems to be a bit broken, this needs the liip_imagine bundle and cache and all to play nicely:

app.js:17 Hello Webpack Encore! Edit me in assets/js/app.js!!!!!
lightspeed.png:1 Failed to load resource: the server responded with a status of 500 ()
asteroid.jpeg:1 Failed to load resource: the server responded with a status of 500 ()
mercury.jpeg:1 Failed to load resource: the server responded with a status of 500 ()

Cheers

Reply

Hey Gary,

It seems we're on Symfony 5.0 in this course code, 5.4 is a good version because it's an LTS (long term support) version. You can see more information about its support here: https://symfony.com/releases . Basically, Symfony 5.4 == Symfony 6.0, i.e. it has the same features but in the 6.0 there's no legacy code, all legacy code from 5.4 was dropped there.

About the docs, yes, I agree... Symfony code base is developing so quick that the docs can't catch up on it, but still the docs leads do a lot of working upgrading the docs to make it simple and cover more features. As you may already understand, it's very difficult to cover 100% of all the features in Symfony components, and so most important ones are covered first. If you have any suggestions how to improve a specific doc page or even want to improve it yourself sending a PR - it would be awesome, feel free to do this in the official Symfony docs repo: https://github.com/symfony/... .

Hm, according to the errors, it seems like you're missing some images. Make sure they exist first.

I hope this helps!

Cheers!

Reply
gazzatav Avatar

Hi Victor
The images are there. The caching/resolving/dataloading part is not working right. This is where the docs don't help. They mention one service and then give an example for a different one, very confusing. Stuff like: You need a psr6cache, here's how you configure aws. You can do it with league/flysystem, here's how you configure oneup/flysystem. (I've tried both).
Running symfony console liip:imagine:cache:resolve -vvv media/cache
OR
Running symfony console liip:imagine:cache:resolve -vvv build/images, I get:
- media/cache[squared_thumbnail_small] (failed) Source image not resolvable "media/cache" in root path(s)
The error message, even with the '-vvv' tells me exactly what I already know. The local server holds on to images as well, even if you clear the cache and the browser cache so if you experiment with changing filenames to see where images are being found (it always finds the space-ice image) you have to restart the server so it's easy to get confused. I copied all the images with their starting name like alien-profile.da9d186f.png and a copy alien-profile.png into both public/build/images and public/media/cache and it still only finds the space-ice even though the html has a path to the correct file when viewed in developer tools in the browser.
Cheers
Gary

Reply

Hey Gary,

It's difficult to say what's wrong, my wild guess is that you might configure paths in a wrong way in your configuration, probably double check them with the paths in the course code of this tutorial.

Also, make sure you're using the Symfony built-in web server, i.e. run it with "symfony serve" command. Otherwise, in case you're using a different web server like Apache or Nginx - you might need additional configuration, especially if you put your Symfony project in a subdirectory, i.e. something like this: http://127.0.0.1:8000/my-project/ - subdirectories in the host may cause such issues, though it's weird if some images works and some are not.

Btw, you can disable files hashing in the webpack.config.js configuration file - it might help with debugging, as your file names will be "alien-profile.png" instead of "alien-profile.da9d186f.png".

I hope this helps!

Cheers!

Reply
gazzatav Avatar

HI Victor
The images in the start folder are hashed, so that is their name. I only removed the hash to test what could be found and where from. I'm using the command symfony server:start -d mostly, sometimes symfony serve -d. This is all local. The missing images are the filtered images like https://localhost:8000/media/cache/resolve/squared_thumbnail_small/article_image/asteroid.jpeg which should come from the twig:
src="{{ article.imagePath|imagine_filter('squared_thumbnail_medium') }}"

The path media/cache etc. is not being generated. So the images are not being loaded/filtered/cached. I noticed just now that there are 1147 logs from the compilation of the service container - I missed them under the 36 deprecation notices - maybe that will take me somewhere!
Cheers

Reply

Hey Gary,

Yeah, check the logs is always a great idea, it may contain some tips there for sure.

Another problem - would be good to make sure all those folders exist and the system can write there, but I suppose you will find problem in logs as well if it's a permission problem.

Cheers!

Reply

For anyone encountering the following error when switching to sqlite as database during setup as described in README.md, i.e. changing the setting for DATABASE_URL in .env.


php bin/console doctrine:migrations:migrate
...
Migration 20180413174059 failed during Execution. Error Migration can only be executed safely on 'mysql'.
...

For me it worked deleting/moving the migration files from src/Migrations, then dropping/recreating the database and generating a new migration for sqlite.


rm src/Migrations/*
php bin/console doctrine:database:drop --force
php bin/console doctrine:database:create
php bin/console doctrine:database:drop
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate

Done.

Reply

Hey Manuel,

Thank you for this tip! Yes, if you're going to use a different from MySQL DB server, migrations won't work, because migrations are tight to MySQL only. So, all the generated migrations are useless for you, you need to drop the incorrect migrations as you suggested, then create the DB and schema via Doctrine commands instead, then generate new migrations for your specific DB provider.

Cheers!

Reply
Pavlo M. Avatar
Pavlo M. Avatar Pavlo M. | posted 1 year ago

Just got this error

The definition for "messenger.receiver_locator" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise
specify a class to get rid of this error.

Any ideas how to fix it?

Reply

Hey Pavlo,

Did you download the course code from the course page and started from start/ directory? Or did you download a fresh version of Symfony? What version is it?

Well, looks like in your system you're trying to access "messenger.receiver_locator". Could you share the config where you're trying to inject it?

Cheers!

Reply
Pavlo M. Avatar

Hey hey, thanks for your quick response!

I fixed the problem by simply removing symfony/messenger `composer remove symfony/messenger` so it's fine now :)

Reply

Hey Pavlo,

Thank you for sharing your workaround with others! Yeah, Messenger isn't required for this course IIRC, so it should be ok :)

Cheers!

Reply
Stefan P. Avatar
Stefan P. Avatar Stefan P. | posted 1 year ago

Problem:
The article images are not loading in... tried to fix it, but nothing really helped...there was an update for the liip/imagine-bundle but this did not help either..What can I do?

Reply

Hey Stefan P.

Do you get any errors on the Browser's console? Could you double-check that your assets were installed, i.e. run yarn install && yarn dev

Cheers!

Reply
Stefan P. Avatar

thnx :)

Reply

Hi, I have a problem.
After I download the course code and setup by README (all command executed successfully) when I open homepage I got the following error:

Argument 1 passed to Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DoctrineParamConverter::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry or null, instance of Doctrine\Bundle\DoctrineBundle\Registry given

Reply

Yeah, composer update helped me. Now all works fine

Reply

Hey maMykola!

Ah, sorry about that! I've been updating some dependencies on these tutorials *just* a little bit so that they work in PHP8. It looks like I got a bad combination of SensioFrameworkExtraBundle and DoctrineBundle or possibly doctrine/persistence. I'll take a look at this and get the download fixed up for others :).

Cheers!

Reply
Gediminas N. Avatar
Gediminas N. Avatar Gediminas N. | posted 2 years ago

When I run composer install during the installation of course files I get this :

Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Package easycorp/easy-log-handler is abandoned, you should avoid using it. No replacement was suggested.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package twig/extensions is abandoned, you should avoid using it. No replacement was suggested.

and I guess because of that I can't use fixtures, I get this -

Libsodium is not available. You should either install the sodium extension, upgrade to PHP 7.2+ or use a different encoder.

I do use PHP 7.4

Reply
Michael V. Avatar

If you are using PHP version 7.2 or greater, then simply add extension=sodium to your php.ini file to make it work. Here is the link to the PHP documentation.

Hope that helps!

Reply

Hey Michael,

Thank you for sharing this link! Yeah, it should help I think... but only if you have that sodium extension installed. I'm afraid that the extension might not be included in PHP installation for some OS, depends on the way you install the PHP I think.

Cheers!

Reply

Hey fUb,

Those are just warning notifications, they mean that those packages are just not maintained anymore, but you still can use them. The real problem is in Libsodium is not available in your system. Are you on Windows OS? What server do you use, XAMPP? It sounds like your PHP version installed does not have that Libsodium installed - you need to install it somehow for your PHP version.

As an alternative solution you may change to a different password encoder, e.g. try "argon2i", in security.yaml:


# config/packages/security.yaml
security:
encoders:
App\Entity\User:
algorithm: argon2i

Does it helped?

Cheers!

Reply
James M. Avatar
James M. Avatar James M. | posted 2 years ago

The starting code in this section, for some reason, the styles aren't loading.

Reply
Pavlo M. Avatar

Faced same issue, but just clear the cache in Chrome and everything worked - *CMD + I* and then refresh the page

1 Reply

Hey James M.!

Hmm. For simplicity, I committed the built Encore assets to the code download so that the site is effectively loading "static" CSS and JS files. I've just double-checked the starting code on my machine, and it *is* working. So, some questions :).

A) What web server are you using? The symfony binary like we are? Or something else?
B) If you try to load one of the CSS files directly - https://127.0.0.1:8000/build/app.css - what do you see? I'm guessing this fails, but what is the error wording exactly?

Sorry about the troubles - but I'm sure it's something minor :).

Cheers!

Reply
Abdul mannan Avatar

I have the same issue. I just downloaded the code and followed the instructions. The css is loading from the localhost url mentioned I am using the symfony binary as well but no css is getting applied.

Reply

Hey Abdul mannan!

Hmmm. So you are able to access the site, but then there are simply no styles? If you open your network tools in your browser and refresh the page, do you see a request failing for app.css? If so, what is the error? Here's an example of what I'm talking about (but my app.css is working - but hopefully you'll see an error of some sort!): https://imgur.com/c1Qg06P

Cheers!

Reply
Abdul mannan Avatar

Hi Ryan

Looks like something is wrong with my chrome. I checked in FF and it worked and along it works fine in incognito Chrome as well. Thanks for looking into it none the less.

Keep up the awesome fantastic work and support

Reply

Ah, super weird! But thanks a lot for the update! If you *do* find the cause, I'd love to know - it might help us debug other users :).

Cheers!

Reply
Ox V. Avatar

Hi Ryan,

I faced the same issue and as Abdul Mannan mentioned, it was working in incognito chrome window, but not on the normal window. Then I hit Ctrl + F5, it started to work fine. So the issue is obvious that old app.css was served from the browser cache. Clearing browser cache fixes the issue.

Reply

Hey Ox V. !

Thanks for following up with your solution! If an "old" app.css is being loaded from cache... then I guess you have done other projects/courses with app.css? That would make sense - your browser might have an app.css cached from a totally different tutorial :P.

Anyways, hopefully this will help others!

Cheers!

Reply
Justin Avatar

The line SITE_BASE_URL=$SITE_BASE_SCHEME://$SITE_BASE_HOST in .env is broken. If I override either SITE_BASE_HOST or SITE_BASE_SCHEME in .env.local, SITE_BASE_URL ends up with the values from .env without taking the overrides. .env.local hasn't been parsed at the time .env is, so it sees the default values from .env. When .env.local is parsed, it's too late, SITE_BASE_URL has already been defined. To fix the images, you can copy the SITE_BASE_URL line to .env.local below the overridden SITE_BASE_HOST and/or SITE_BASE_SCHEME without changing it and the images should start working. Alternatively, you could change the definition of parameters.uploads_base_url to '%env(SITE_BASE_SCHEME)%://%env(SITE_BASE_HOST)%/uploads' in services.yaml and remove SITE_BASE_URL all together.

Reply

Hey Justin!

Yea, I totally borked this in the mailer tutorial when I originally did this. It's not a huge deal... but it definitely did *not* work as I originally intended. We're going to update the starting code in this tutorial (probably to use your parameters.uploads_base_url version) so that it works smoothly here.

Thanks for the post!

Cheers!

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

This tutorial also works well for Symfony 6!

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.4.0 || ^8.0.0",
        "ext-iconv": "*",
        "antishov/doctrine-extensions-bundle": "^1.4", // v1.4.3
        "aws/aws-sdk-php": "^3.87", // 3.133.20
        "composer/package-versions-deprecated": "^1.11", // 1.11.99
        "doctrine/annotations": "^1.0", // 1.12.1
        "doctrine/doctrine-bundle": "^2.0", // 2.2.3
        "doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // 2.2.2
        "doctrine/orm": "^2.5.11", // 2.8.2
        "easycorp/easy-log-handler": "^1.0", // v1.0.9
        "http-interop/http-factory-guzzle": "^1.0", // 1.0.0
        "knplabs/knp-markdown-bundle": "^1.7", // 1.9.0
        "knplabs/knp-paginator-bundle": "^5.0", // v5.4.2
        "knplabs/knp-snappy-bundle": "^1.6", // v1.7.1
        "knplabs/knp-time-bundle": "^1.8", // v1.16.0
        "league/flysystem-aws-s3-v3": "^1.0", // 1.0.24
        "league/flysystem-cached-adapter": "^1.0", // 1.0.9
        "league/html-to-markdown": "^4.8", // 4.9.1
        "liip/imagine-bundle": "^2.1", // 2.5.0
        "oneup/flysystem-bundle": "^3.0", // 3.7.0
        "php-http/guzzle6-adapter": "^2.0", // v2.0.2
        "phpdocumentor/reflection-docblock": "^5.2", // 5.2.2
        "sensio/framework-extra-bundle": "^5.1", // v5.6.1
        "symfony/asset": "5.0.*", // v5.0.11
        "symfony/console": "5.0.*", // v5.0.11
        "symfony/dotenv": "5.0.*", // v5.0.11
        "symfony/flex": "^1.9", // v1.17.5
        "symfony/form": "5.0.*", // v5.0.11
        "symfony/framework-bundle": "5.0.*", // v5.0.11
        "symfony/mailer": "5.0.*", // v5.0.11
        "symfony/messenger": "5.0.*", // v5.0.11
        "symfony/monolog-bundle": "^3.5", // v3.6.0
        "symfony/property-access": "5.0.*|| 5.1.*", // v5.1.11
        "symfony/property-info": "5.0.*|| 5.1.*", // v5.1.10
        "symfony/routing": "5.1.*", // v5.1.11
        "symfony/security-bundle": "5.0.*", // v5.0.11
        "symfony/sendgrid-mailer": "5.0.*", // v5.0.11
        "symfony/serializer": "5.0.*|| 5.1.*", // v5.1.10
        "symfony/twig-bundle": "5.0.*", // v5.0.11
        "symfony/validator": "5.0.*", // v5.0.11
        "symfony/webpack-encore-bundle": "^1.4", // v1.11.1
        "symfony/yaml": "5.0.*", // v5.0.11
        "twig/cssinliner-extra": "^2.12", // v2.14.3
        "twig/extensions": "^1.5", // v1.5.4
        "twig/extra-bundle": "^2.12|^3.0", // v3.3.0
        "twig/inky-extra": "^2.12", // v2.14.3
        "twig/twig": "^2.12|^3.0" // v2.14.4
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.0", // 3.4.0
        "fakerphp/faker": "^1.13", // v1.13.0
        "symfony/browser-kit": "5.0.*", // v5.0.11
        "symfony/debug-bundle": "5.0.*", // v5.0.11
        "symfony/maker-bundle": "^1.0", // v1.29.1
        "symfony/phpunit-bridge": "5.0.*", // v5.0.11
        "symfony/stopwatch": "^5.1", // v5.1.11
        "symfony/var-dumper": "5.0.*", // v5.0.11
        "symfony/web-profiler-bundle": "^5.0" // v5.0.11
    }
}