Chapters
23 Chapters
|
2:22:24
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.4.1
Subscribe to download the code!Compatible PHP versions: ^7.4.1
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
19.
Data Fixtures
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!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial also works great for Symfony 6!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.4.1",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^2.1", // 2.1.1
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.7", // 2.8.2
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"knplabs/knp-time-bundle": "^1.11", // v1.16.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"sentry/sentry-symfony": "^4.0", // 4.0.3
"stof/doctrine-extensions-bundle": "^1.4", // v1.5.0
"symfony/asset": "5.1.*", // v5.1.2
"symfony/console": "5.1.*", // v5.1.2
"symfony/dotenv": "5.1.*", // v5.1.2
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.1.*", // v5.1.2
"symfony/monolog-bundle": "^3.0", // v3.5.0
"symfony/stopwatch": "5.1.*", // v5.1.2
"symfony/twig-bundle": "5.1.*", // v5.1.2
"symfony/webpack-encore-bundle": "^1.7", // v1.8.0
"symfony/yaml": "5.1.*", // v5.1.2
"twig/extra-bundle": "^2.12|^3.0", // v3.0.4
"twig/twig": "^2.12|^3.0" // v3.0.4
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.0
"symfony/debug-bundle": "5.1.*", // v5.1.2
"symfony/maker-bundle": "^1.15", // v1.23.0
"symfony/var-dumper": "5.1.*", // v5.1.2
"symfony/web-profiler-bundle": "5.1.*", // v5.1.2
"zenstruck/foundry": "^1.1" // v1.5.0
}
}
15 Comments
After executing "
composer require orm-fixtures --dev"i run into the following error:
PHP Fatal error: During class fetch: Uncaught ReflectionException: Class "Symfony\Component\Validator\Mapping\Loader\AutoMappingTrait" not found while loading "Symfony\Bridge\Doctrine\Validator\DoctrineLoader". in /home/renevorndran/code-symfony-doctrine/start/vendor/symfony/error-handler/DebugClassLoader.php:346Any Ideas how to solve it?
Hey Rene V.!
Yikes! That's a scary error! My guess is that there is some version problem - like a bug that was probably fixed in some later version of a library. For example, I found this - https://github.com/symfony/symfony/issues/41796 - and it looks like your issue might be fixed with DoctrineBundle 2.43. or higher. Try:
composer update doctrine/doctrine-bundleand let me know if it helped :).Cheers!
I also found that tip but did not manage to get that dependancies to a working state. Updating doctrine-bundel told me to also update doctrine-extension-bundle, so i ran the following:
symfony composer update doctrine/doctrine-bundle stof/doctrine-extensions-bundle -wBut the error still pops up.
My composer.lock currently looks like: https://pastebin.com/2Ex0Lfnu
Currently running PHP 8.1.2 (cli) so i even tried with <i>--ignore-plaform-reqs</i> because the following problem appeared:
<blockquote>Problem 1
</blockquote>
Hey Rene,
From the log, looks like your PHP version that is 8.1.2 does not fit requirements for those bundles. "stof/doctrine-extensions-bundle" of v1.5.0 does not work on PHP 8 yet. But for the next available version of stof/doctrine-extensions-bundle which is v1.6.0 you need to have symfony/config 5.2, but if you're using project code from this course you most probably have 5,1 installed. So, to be able to upgrade "stof/doctrine-extensions-bundle" to 1.6.0 at least - you need to upgrade Symfony packages first, at least to 5.2 version.
I hope this is clear and helps!
Cheers!
Ahh actually it seems to be that easy...
did the trick! Thank you guys!
Hey Rene,
If you're talking about changing "extra.symfony.require" - yes, you have to match the version you use for "symfony/*" packages. If you changed their constraints - you also need to change that place too to match them.
Anyway, I'm happy to hear you were able to fix it finally, good job!
Cheers!
Ran into issue when running composer require orm-fixtures --dev, gave huge nasty error. Solution at https://stackoverflow.com/q... fixed it for me. Just putting here in case anyone else runs into issue :)
Hey Sean!
Thanks for the post here! Thanks to this ping, I'm now following up and pushing on the fix in doctrine/data-fixtures so we can get it as soon as possible - https://github.com/doctrine...
In the mean time, the StackOverflow you linked to has a few workarounds. Not ideal, but doable :).
Thanks!
Hello, first of all thank you for this tutorial. I just want to report this little "mistake" in AppFixtures.php file `$entityManager->persist($question);` you forgot to rename `$entityManager` to `$manager` ^^.
Hey @Abdel!
<s>Ah! You're absolutely right! I'm not sure how that happened :). We'll get it fixed up asap!</s>
<s>Thanks for the note!</s>
EDIT: I replied too soon! Yes, when we paste the code in, we paste in
$entityManager- it's in this code block - https://symfonycasts.com/screencast/symfony-doctrine/fixtures#codeblock-e8f469f223 - but we fix it in the very next code block:And the next code block fixes it https://symfonycasts.com/screencast/symfony-doctrine/fixtures#codeblock-b3ba438c35
So, I think it's all correct - but I appreciate you keeping a close eye on things!!
Cheers!
Hey Nicolas,
Glad you figured it out, well done! Yeah, when you work with entities - you should pass a real objects instead of just ids :)
Cheers!
Hey Nicolas,
It's clearly from the error that the method setGenre() expects an instance of MusicGenre but got string... First of all, I'd recommend you to debug what is that string exactly, it will give you more context. For this, temporarily remove that type MusicGenre type from the setGenre() and add dd($genre) into that method to dump the actual value. Then run the same steps to see more context now - it should help you to figure out what you do wrong.
If it still does not help, try to see all your setGenre() method calls in code, in particular, in your fixtures code to see where you pass the string instead of an object :)
I hope this helps!
Cheers!
"Houston: no signs of life"
Start the conversation!