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!
06.
Entity Class
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 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
}
}
29 Comments
is there a detailed idea of how to publish a ready-made symfony-5 application on a shared hosting and so that it works exactly the same as on a local one ???
Hey there!
Could you describe your idea a bit more? :) What do you mean about "it works exactly the same as on a local one"? The Symfony application should work exactly as on your local machine, but it depends on the server/php configuration. What differences do you have?
Cheers!
I made a mistake during make:entity > Question I named the column asked_at instead of askedAt.
It generates me some errors and diffculties for rest of the tutos (chapter 21 particulary).
I tried to rename it in the Question entity and then launch migration and then migrate after, but the field name doesn't update in the database.
How can I roll back and "re-make" the question Entity class or just rename the askedAt column ?
Hey Robin R.!
Ah, excellent question! So, a few things:
You probably updated the Question entity correctly :). By default (well, more accurately, thanks to this line of config that lives on your config/packages/doctrine.yaml file - https://github.com/symfony/recipes/blob/master/doctrine/doctrine-bundle/2.4/config/packages/doctrine.yaml#L10 ) when Doctrine creates a table from a class or a column from a property name, it "underscores" it. So if you have an askedAt property, it creates an asked_at column in the database. So, it's very likely that you updated the Question entity just fine... but that the column in the database doesn't need to change. No migration needed!
This, as you correctly guessed, needs to be done by hand :). If you had noticed the mistake immediately, you could have always hit Ctrl+C to exit the make:entity process and then rolled back via git (
git checkout src/Entity/Question.php) the changes to your entity... then re-ran make:entity.I hope this helps!
Cheers!
Ryan - I hope you can point me at some help. As I was using the https://symfony.com/doc/cur... - this did not generate the repositories in this video - is there a way to generate those form the Entity Classes I now have?
found an answer
php bin/console make:entity --regenerate App
Hey @desc
Good catch! Glad you were able to find the solution yourself :) Another alternative solution would be to copy/paste the code from another repository class and change class names.
Cheers!
Thank you - can you point me to a symfony queries place to ask general questions that may not be specific to a video? Much appreciated. Enjoying the learning and progress on my project.
Hey @desc,
Because of our limited bandwidth we do not answer questions related to user personal projects, but if it's related to our videos - the best place to ask questions is below the video in "Conversation" section. If you have other Symfony-related questions regarding your private projects and do not related to our screencasts - please, ask them in Symfony Slack channel or in StackOverflow, you can find them here: https://symfony.com/support
Thanks for understanding!
Cheers!
thank you
Hello There
With mysql Server_Version 5.7 or 8.0 on doctrine.yaml file when i am trying to make:entity, I am getting following error -
In FileLoader.php line 173:
The file "C:\wamp64\www\Symfony001\Symfony-Doctrine\config/packages/doctrine.yaml" does not contain valid YAML: A Y
AML file cannot contain tabs as indentation in "C:\\wamp64\\www\\Symfony001\\Symfony-Doctrine\\config/packages/doct
rine.yaml" at line 8 (near " server_version: '5.7'") in C:\wamp64\www\Symfony001\Symfony-Doctrine\config/packages/
doctrine.yaml (which is being imported from "C:\wamp64\www\Symfony001\Symfony-Doctrine\src\Kernel.php").
In YamlFileLoader.php line 745:
The file "C:\wamp64\www\Symfony001\Symfony-Doctrine\config/packages/doctrine.yaml" does not contain valid YAML: A Y
AML file cannot contain tabs as indentation in "C:\\wamp64\\www\\Symfony001\\Symfony-Doctrine\\config/packages/doct
rine.yaml" at line 8 (near " server_version: '5.7'").
In Parser.php line 152:
A YAML file cannot contain tabs as indentation in "C:\\wamp64\\www\\Symfony001\\Symfony-Doctrine\\config/packages/d
octrine.yaml" at line 8 (near " server_version: '5.7'").
Please let me know how to resolve this issue.
Thanks
Hey Jayant B.
You only need to update your `config/packages/doctrine.yaml` so it doesn't contain tabs, and use "spaces" instead.
Cheers!
Thank you! That worked!
Cheers!
Hi!
After I create the entity with php bin/console make:entity , I get this error which will not allow me to create the fields!
http://prntscr.com/10xmj37
http://prntscr.com/10xmrg0
Hey @Kleo
Which php version do you use?
Cheers!
Hi Vladimir,
I have this same error and i run php 8.0.3.
Cheers!
Hey @Jean Charles,
Thanks for the tip. For PHP 8, I'd recommend you to upgrade php parser library with following command
<br />composer upgrade nikic/php-parser<br />This should fix this type of issues =)
Cheers!
QUESTION! Is it required to have the getters and setters in the class? I prefer using traits for better organization and reuse of my code!
Hey mikesmit1992!
Traits work perfectly fine with Doctrine :). So you could move the properties+getters & setters into a trait and then use that trait from your entity (or from multiple entities). You are also free to make your properties public and not have any getter and setter methods at all. So basically... you can do whatever you want ;).
Cheers!
Heyho!
I get the following error every time I use the "./bin/console make:entity" command: https://prnt.sc/w67v2e
Do you know why and how I can fix it?
Hey Johannes!
That is SUPER weird... like, it's one of those errors that should *never* happen: a file that should 100% be there is not (and so Composer is exploding). Honestly, I would try removing your vendor/ directory entirely and then re-running "composer install". I bet something weird just happened with Composer.
Let me know!
Cheers!
Hi!
New property name (press <return> to stop adding fields):
> name
In Validator.php line 158:
Argument 2 passed to Symfony\Bundle\MakerBundle\Validator::validateDoctrineFieldName() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance
of Doctrine\Bundle\DoctrineBundle\Registry given, called in /home/emilio/Sites/symfony_doctrine/vendor/symfony/maker-bundle/src/Maker/MakeEntity.php on line 303
Hi @Emilio!
Are you running the "code download" from this tutorial? Or are you working on your own project? If you are getting this from the code download, please let me know! That shouldn't happen! If you are getting this in your own project, try upgrading to at least MakerBundle 1.21.0, which fixed this bug https://github.com/symfony/...
Cheers!
i use code from this lesson and have the same issue.
i updated version of symfony/maker-bundle to ^1.21.1 and it works greate.
Using course zip file for project.
Argument 2 passed to Symfony\Bundle\MakerBundle\Validator::validateDoctrineFieldName() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\Doctrine
Bundle\Registry given, called in /Users/kevingehrke/Projects/SymfonyCasts/code-symfony-doctrine/start/vendor/symfony/maker-bundle/src/Maker/MakeEntity.php on line 303
Update to symfony/maker-bundle to ^1.21.1 resolved issue.
Hey KGehrke,
We're sorry to hear you had an issue, but I'm happy that you were able to fix it with the solution from Smidl.
Could you provide a bit more info about the problem? What exactly did you do when see this error? Running "composer install" command? Are you in start/ directory of the downloaded course code?
Cheers!
Hey victor!
Just following up - we were a bit slower because of the holidays :). Victor checked into this further and found the problem - as you suspected a bug in the MakerBundle version we were using (if you're using a new doctrine/persistence package).
I've just updated the code download so that it should work out of the box. Thanks for the report!
Cheers!
"Houston: no signs of life"
Start the conversation!