// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"sensio/framework-extra-bundle": "^5.1", // v5.1.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.0.4
"symfony/console": "^4.0", // v4.0.14
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.0.14
"symfony/lts": "^4@dev", // dev-master
"symfony/twig-bundle": "^4.0", // v4.0.4
"symfony/web-server-bundle": "^4.0", // v4.0.4
"symfony/yaml": "^4.0" // v4.0.14
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.4
"fzaninotto/faker": "^1.7", // v1.7.1
"symfony/debug-bundle": "^3.3|^4.0", // v4.0.4
"symfony/dotenv": "^4.0", // v4.0.14
"symfony/maker-bundle": "^1.0", // v1.4.0
"symfony/monolog-bundle": "^3.0", // v3.1.2
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.0.4
"symfony/stopwatch": "^3.3|^4.0", // v4.0.4
"symfony/var-dumper": "^3.3|^4.0", // v4.0.4
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.0.4
}
}
38 Comments
It took me a while to figure out that the Entity autowiring requires sensio/framework-extra-bundle.
Hey Sander H.
Why was that? Do you think we missed something?
Cheers!
Well, I was using the tutorials to make a project of my own. In the sample code, the composer.json contains the sensio/framework-extra-bundle, but my project didn't.
In the text of this video, it says:
"In addition to that, if you type-hint an entity class, Symfony will automatically query for that entity."
Maybe you could rewrite it to something along the lines of:
"In addition to that, if you type-hint an entity class, (and if you have sensio/framework-extra-bundle installed) Symfony will automatically query for that entity."
Because, if I understand it correctly, it is not a core feature of Symfony.
Ohh, I understand it now. You're right it's not part of the core of Symfony but it comes by default when you install a fresh web version of Symfony.
Check it out: https://github.com/symfony/...
Anyways, I'll talk about it internally with the staff
Cheers!
Hey, great tutorials, awesome job! :)
But I must report that this video fails to load with the message: "The media could not be loaded, either because the server or network failed or because the format is not supported."
I've tried with both firefox and chrome, it fails consistently.
Please, try to fix it.
Thanks in advance and keep up with the great work! :)
Hey Miljan,
We're sorry about it and thank you for reporting this! Do you have such problem with only *this* video or every video on our website? If only this one - this sounds like a temporary problem that might cause with problems on Vimeo side - the platform we use to host our videos. I just double-checked and this video works for me fine, please, try again and let us know if you still have this problem. Btw, sometimes refreshing the page a few times might help to solve this issue. Or try to open the video in another browser or Chrome Incognito mode.
Cheers!
Is it not easier to do?
`
public function FindAllPublishedOrderByNewest()
{
}
private function FindAllPublished()
{
}`
Cheers! :p
Hey Virgile,
Easier in your example, but not so flexible :) What if you would like to apply a few logics that you separated with a few private methods, like find "all published" but also for the "specific author". If you would call createQueryBuilder() in both private methods - you can't reuse them in FindAllPublishedOrderByNewest(). That's why apply only WHERE clouses in private reusable methods is more flexible as you're not blocking it with createQueryBuilder().
I hope this makes sense for you :)
Cheers!
Hey Victor,
Thanks you a lot for the time you took to answer me !
It is now more clear to me !
Cheers !
Hey Virgile,
Glad it helped!
Cheers!
I am not sure why i do not get a notification for a reply on this message board, and I can't remember what where i posted my question to revisit. Kindly thanks!
Hey Dung,
It's Disqus comments block, you can find your latest comments in the right sidebar on this page, click on your name in the right top corner of this Disqus block, then choose "Profile". Or simply click on your avatar picture or full name in your comment. In the right popup sidebar you'll find "Comments" tab with your latest comments - the easiest way to find your latest comments. About notifications, I think you need to check disqus settings for your account.
I hope this helps!
Cheers!
I've run into a show stopping issue. When pulling $slug out of injection and changing to Article $article then $article->getSlug(). I refresh my page and get a big ugly error that I cannot quite decipher myself.
Error: During class fetch: Uncaught ReflectionException: Class Symfony\Component\Form\FormTypeGuesserInterface not found in /var/www/symfony/the_spacebar/vendor/symfony/doctrine-bridge/Form/DoctrineOrmTypeGuesser.php:25 Stack trace: #0 /var/www/symfony/the_spacebar/vendor/symfony/debug/DebugClassLoader.php(156): require('/var/www/symfon...') #1 [internal function]: Symfony\Component\Debug\DebugClassLoader->loadClass('Symfony\\Bridge\\...') #2 [internal function]: spl_autoload_call('Symfony\\Bridge\\...') #3 /var/www/symfony/the_spacebar/vendor/symfony/config/Resource/ClassExistenceResource.php(78): class_exists('Symfony\\Bridge\\...') #4 /var/www/symfony/the_spacebar/vendor/symfony/dependency-injection/ContainerBuilder.php(353): Symfony\Component\Config\Resource\ClassExistenceResource->isFresh(0) #5 /var/www/symfony/the_spacebar/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(336): Symfony\Component\DependencyInjection\ContainerBuilder->getReflectionClass('Symfony\\Bridge\\...', false) #6 /var/www/symf
Any thoughts on this?
seems to be an active bug with this: https://github.com/symfony/...
I had to:
composer require validator
composer require symfony/form
I also did
composer require symfony/phpunit-bridge
but i'm not sure if that one was needed.
Just FYI in case anyone else encounters this with PHP 7.2/7.3/7.4
Hey Ryan S. ,
Yes, you're right! It seems like you were found the correct issue on GitHub. For now, you have a few options how to solve this:
1. Temporarily install missing dependencies that causes this error. It looks like in this case just execute "composer require forms"
2. Downgrade your PHP version. Affected version are 7.3.7 and 7.2.20 as you can see in the issue, so you should avoid them
3. Wait for 7.2.21 / 7.3.8 release and upgrade your PHP version
Cheers!
I required validator too before it would work.
I know i could downgrade PHP or wait and upgrade PHP but it sounded like from that github convo that this change in PHP handling of the error is going to come one way or another at some point. I find it odd that if doctrine actually requires these packages why they aren't installed as dependencies at time of install?
Hey Ryan S.,
> I find it odd that if doctrine actually requires these packages why they aren't installed as dependencies at time of install?
Some dependencies are optional, and you need to install them only if you use some specific features. It allows to keep library dependencies slim. But due to that BC break some things were broken. Anyway, let's follow that threat for now to track the problem and its implementation.
Cheers!
Hey man, can you try it out on PHP 7.1? There is a bug between Symfony and PHP latest version
Cheers!
I'm sure that's the issue, I just don't want to downgrade my PHP to test. when i included all the required dependencies that I listed it worked.
Ohh, that's interesting. Can you tell me on which Symfony version are you running?
4.3.2
Two small questions about that "slug" placeholder. What will happen if my route would be looking like this: "article/{id}/{slug}". How can I tell symfony which placeholder should use to get a correct DB record?
Second question is. Why in this tutorial to identification article you using "title" not article "id"? I thought searching by id in DB is much quicker then string? Is not a better practise to have URL like this"article/{id}/{slug}" and have only "id" unique?
Hey Dominik!
Good questions!
You have a few options. First, if you do nothing, it will try to use both columns - e.g.
WHERE id = {id} AND slug = {slug}. In practice, that's probably fine, though technically using both is unnecessary.To control it further, you can use a
@ParamConverterannotation to tell Symfony which field to use https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#fetch-via-an-expressionOr, you can simply skip the "param conversion" and use the
$idvariable to manually query in your controller.By "title" - do you mean the "slug"? You're right that we are querying via the slug (the "clean" article string) not the id. But, that is not slower than querying for id because of one important reason: In Article, above the slug property, we have
unique=true. This creates unique index in the database, which means querying by slug is super fast.Let me know if that makes sense!
Cheers!
You are right. I forgot about index. Regards
is creating a function that getOrCreate just one object of the query builder can be considered a practice for the single tone pattern design?
Hey Ahmed,
Not really, singleton pattern means you design the class in such way that you cannot create more than one object of it - it's just impossible because you make its constructor private and the only way to create an object - use a specific public static method that implements some logic. But here we just create a helper method that implement this behavior, but you can easily bypass it - just cal create method directly instead of calling this getOrCreate() one. So, singleton pattern is something different :)
Cheers!
awesome! thank you :)
You're welcome ;)
Cheers!
Hi,
Is there a way to change the "not found by the @ParamConverter annotation" message ?
Thanks.
Hey Chuck norris
I'm not sure if that's easy to achieve but those messages are not visible by users when you are on production mode, they will see your 404 template instead
Cheers!
"....Symfony will automatically query for that entity. How? It looks at all of the route's placeholder values - which is just one in this case, {slug} - and creates a query where the slug field matches that value:..."
Does this mean I should add column to index because Symfony create query like
"SELECT * FROM table WHERE table.slug LIKE '%slug%' "?
and if database is big without table.slug set as index it will be hard query...?
Hey Aleksandr T. ,
Yes, it's a good idea to add index for this field. Well, actually the "slug" field should be unique, and if you already made this fields unique - that means it's already indexed.
Cheers!
When I use this logic then phpstorm stops prompting orm class fields (eg inside addIsPublishedQueryBuilder function). Do I do anything wrong?
Hey bartek
Try adding PHPDoc return type to that method
Cheers!
I've got this but don't work.
Do you have the "PHP annotations" plugin installed?
Yes I've got it ;)
Great! so it's autocompleting now?
"Houston: no signs of life"
Start the conversation!