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!
14.
Reusing Query Logic & Param Converters
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
}
}
8 Comments
`
public function findAllAskedOrderedByNewest()
`
QueryBuilder $qb does not need to be specified for addIsAskedQueryBuilder because getOrCreateQueryBuilder is already specified
right ?
Hey Sandor,
Yes, you're correct! The QueryBuilder instance is already created in getOrCreateQueryBuilder() and because we return it there - we can just use it upstream in addIsAskedQueryBuilder() and return it again so we could continue with the chain in findAllAskedOrderedByNewest() as well :)
Cheers!
Once a query was made, $qb will return to be null?
In witch conditions $qb will be null?
Thank you in advance
Hey zahariastefan462
I believe you got confused by our custom private method
getOrCreateQueryBuilder(). It accepts an optional QueryBuilder but it will alwasy return one.Cheers!
Thank you for reply. I think I understood now.
I don't understand why you don't delete the ->andWhere('q.askedAt IS NOT NULL') line. Isn't that the purpose of the addIsAskedQueryBuilder to be able to avoid duplicate code?
Hi @Farah!
OMG, that's 100% my fault! I was so focused on the refactoring that I forget to actually take *advantage* of the refactoring. Yes, I intended to remove, because it's now redundant. I'll add a note to the video so that others don't get confused.
Thanks for the message on this!
Thank you very much for your reply! I just got confused for a second. I totally get being focused on a task and forgetting everything else haha! Keep up the amazing tutorials they‘re seriously the best out there and actually help me so much at me new job!
"Houston: no signs of life"
Start the conversation!