Chapters
27 Chapters
|
2:45:18
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
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!
10.
Filtering to Return only Approved Answers
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.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.3", // v3.3.0
"composer/package-versions-deprecated": "^1.11", // 1.11.99.3
"doctrine/doctrine-bundle": "^2.1", // 2.4.2
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.1.1
"doctrine/orm": "^2.7", // 2.9.5
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"knplabs/knp-time-bundle": "^1.11", // v1.16.1
"pagerfanta/doctrine-orm-adapter": "^3.3", // v3.3.0
"pagerfanta/twig": "^3.3", // v3.3.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"stof/doctrine-extensions-bundle": "^1.4", // v1.6.0
"symfony/asset": "5.3.*", // v5.3.4
"symfony/console": "5.3.*", // v5.3.7
"symfony/dotenv": "5.3.*", // v5.3.7
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.3.*", // v5.3.7
"symfony/monolog-bundle": "^3.0", // v3.7.0
"symfony/runtime": "5.3.*", // v5.3.4
"symfony/stopwatch": "5.3.*", // v5.3.4
"symfony/twig-bundle": "5.3.*", // v5.3.4
"symfony/validator": "5.3.*", // v5.3.14
"symfony/webpack-encore-bundle": "^1.7", // v1.12.0
"symfony/yaml": "5.3.*", // v5.3.6
"twig/extra-bundle": "^2.12|^3.0", // v3.3.1
"twig/string-extra": "^3.3", // v3.3.1
"twig/twig": "^2.12|^3.0" // v3.3.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.0
"symfony/debug-bundle": "5.3.*", // v5.3.4
"symfony/maker-bundle": "^1.15", // v1.33.0
"symfony/var-dumper": "5.3.*", // v5.3.7
"symfony/web-profiler-bundle": "5.3.*", // v5.3.5
"zenstruck/foundry": "^1.1" // v1.13.1
}
}
5 Comments
Hi
Great and very helpful course. I have a question related to this lecture:
Shouldn't the method
getApprovedAnswer()be inQuestionRepository? I thought that Entity classes should contain only the data related to the table... and helper methods (I considergetApprovedAnswer()as a helper method, please correct me if I am wrong) should go in Repository classes...Is there any "rule" or best practice?
Cheers.
Hey t5810,
Good question :) Yes, usually all the query logic is indeed should be placed in the entity repository class... though doing something like this in entities is kinda fine in specific cases. Well, first of all, we showed this for the learning purposes :) It might be a handy shortcut method that you can call right from the entity class. But you should understand its cons and pros. If you have a big collection - it might be overkill to do something like this, and so it's recommended to use Doctrine Criteria that we will show in the next chapter :) And thanks to them, you can move this logic out from entity class to the repository class so that technically you will just have almost no logic in the entity class, just a shortcut. In some cases it might be useful, but you totally can replace it with a custom repository method that you will call in your controller if you can - it would be the most recommended and straightforward way.
Cheers!
btw: do our entities have to be in the App\Entity namespace?
Excellent question!
They do not. This is controlled in your
config/packages/doctrine.yamlfile: https://github.com/symfony/recipes/blob/master/doctrine/doctrine-bundle/2.4/config/packages/doctrine.yaml#L13-L16You can see both where the directory and namespace "prefix" is listed. Change those and you can have your entities in whatever directory and namespace you want (or duplicate this entire block and load entities from App\Entity AND also somewhere else).
Cheers!
"Houston: no signs of life"
Start the conversation!