Chapters
20 Chapters
|
1:53:05
|
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!
This tutorial works perfectly with both Symfony 7 & 8!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"php-cs-fixer/shim": "^3.46", // v3.46.0
"phpdocumentor/reflection-docblock": "^5.3", // 5.3.0
"phpstan/phpdoc-parser": "^1.25", // 1.25.0
"symfony/asset": "7.0.*", // v7.0.3
"symfony/asset-mapper": "7.0.*", // v7.0.2
"symfony/console": "7.0.*", // v7.0.2
"symfony/dotenv": "7.0.*", // v7.0.2
"symfony/flex": "^2", // v2.4.3
"symfony/framework-bundle": "7.0.*", // v7.0.2
"symfony/monolog-bundle": "^3.0", // v3.10.0
"symfony/property-access": "7.0.*", // v7.0.0
"symfony/property-info": "7.0.*", // v7.0.0
"symfony/runtime": "7.0.*", // v7.0.0
"symfony/serializer": "7.0.*", // v7.0.2
"symfony/stimulus-bundle": "^2.13", // v2.13.3
"symfony/twig-bundle": "7.0.*", // v7.0.0
"symfony/ux-turbo": "^2.13", // v2.13.2
"symfony/yaml": "7.0.*", // v7.0.0
"symfonycasts/tailwind-bundle": "^0.7.1", // v0.7.1
"twig/extra-bundle": "^2.12|^3.0", // v3.8.0
"twig/twig": "^2.12|^3.0" // v3.8.0
},
"require-dev": {
"symfony/debug-bundle": "7.0.*", // v7.0.0
"symfony/maker-bundle": "^1.52", // v1.53.0
"symfony/stopwatch": "7.0.*", // v7.0.0
"symfony/web-profiler-bundle": "7.0.*" // v7.0.2
}
}
6 Comments
Hi,
thank you for this very interesting video.
There are some places in my Symfony App that needs to be replaced by enums. However how do I have to make sure that my entities are loaded correctly from the database?
Suppose I have my Starships persisted in a database and the attribute status WAS of type string. How do I take care that the string is correctly transformed into an enum?
Thanks
Oliver
Hey Oliver,
That's a fair question if I understand it correctly :) If you're worry about data loss - make sense. That's easy to implement it on an empty DB or when you create a new column that just does not exist on production yet. But if you already have some VARCHAR strings that you want to properly convert to ENUM. First of all, IIRRC the migration should do all the job for you, you just need to create the full ENUM, i.e. ENUM with all the possible values on your production. here's the steps to follow:
SELECT DISTINCT status FROM your_table.You will need to dobule-check the migration, e.g. create some fake data locally, try to migrate and see if that lead to any data loss or no. If everything work correctly and you covered all the possible values - that just should work for prod as well.
I hope this helps!
Cheers!
Hi desanchextorres,
thank you very much für this adivse.
I tried to create a new field first, that is of type enum, but I stopped with the error, that with
symfony console make:entityI received the error
[ERROR] Class "ExerciseCategory" doesn't exist; please enter an existing full class name.However it does exist.
How can I reference enums in make:entity correctly?
For example my enum is located under
src/Entity/ExerciseCategory.php
Oliver
Hey Oliver,
It should work with just class name, i.e. ExerciseCategory should be ok, but please double check that you don't have any misprints in it or in the file name and class name in that file. Also, that entity should be in
src/Entity/ExerciseCategory.phpand hasApp\Entitynamespace there. If still no success, probably try to update the maker bundle, not sure why it does not work for you.If just class name does not work:
You can also try to specify the full class name like:
But it's a weird error, because even if the file does not exist, it would still create it then. So I bet you just made a misprint somewhere :)
Btw,
make:entity --helpsometimes may help.Cheers!
Hi Victor,
I guess I was not precise enough in my description:
I have en existing entity:
and I have a new created enum
Now I want to add a new attribute to entity Exercise that is of type ExerciseCategory. For this I wanted to use
symfony console make:entity->
I am pretty sure, that it will work manually by creating the attribute exerciseCategory like this
private enum ExerciseCategory exerciseCategory;by hand. But I wanted to try it with the console command.
Hey Oliver,
Ah, I see now :) OK, first of all ExerciseCategory is not an entity, right? That's why it should not be inside the src/Entity/ class... Create a different folder for it in the src/ e.g. src/Enums/ or src/Model/ or src/Category/ and move that file there. Don't forget to change the namespace correspondingly!
Next, run that make:entity command again, and when you will choose
enum- write the full namespace to the file, e.g.App\Enums\ExerciseCategory. In some cases, you may need to escape back slashes. So if that will not work - try:App\\Enums\\ExerciseCategory.Cheers!
"Houston: no signs of life"
Start the conversation!