Chapters
28 Chapters
|
2:24:59
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
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!
02.
DoctrineExtensions: Sluggable
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 course is built on Symfony 3, but most of the concepts apply just fine to newer versions of Symfony.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"symfony/symfony": "3.4.*", // v3.4.49
"doctrine/orm": "^2.5", // 2.7.5
"doctrine/doctrine-bundle": "^1.6", // 1.12.13
"doctrine/doctrine-cache-bundle": "^1.2", // 1.4.0
"symfony/swiftmailer-bundle": "^2.3", // v2.6.7
"symfony/monolog-bundle": "^2.8", // v2.12.1
"symfony/polyfill-apcu": "^1.0", // v1.23.0
"sensio/distribution-bundle": "^5.0", // v5.0.25
"sensio/framework-extra-bundle": "^3.0.2", // v3.0.29
"incenteev/composer-parameter-handler": "^2.0", // v2.1.4
"composer/package-versions-deprecated": "^1.11", // 1.11.99.4
"knplabs/knp-markdown-bundle": "^1.4", // 1.9.0
"doctrine/doctrine-migrations-bundle": "^1.1", // v1.3.2
"stof/doctrine-extensions-bundle": "^1.2" // v1.3.0
},
"require-dev": {
"sensio/generator-bundle": "^3.0", // v3.1.7
"symfony/phpunit-bridge": "^3.0", // v3.4.47
"nelmio/alice": "^2.1", // v2.3.6
"doctrine/doctrine-fixtures-bundle": "^2.3" // v2.4.1
}
}
12 Comments
Wouldn't a better practice be to append genus-id rather than adding a new column to the database?
Hey @Daniel
What you mean by "Append genus-id"? It's a common practice to store the slug in a field so you can ensure two things
1) All slugs are unique
2) A slug won't change if you edit such record
Cheers!
Hello,
I'm trying to start that code on symfony 4, but I got this error:
Cannot autowire service "App\Service\MarkdownTransformer": argument "$cache" of method "__construct()" references interface "Doctrine\Common\Cache\Cache" but no such service exists. You should maybe
alias this interface to one of these existing services: "annotations.filesystem_cache", "annotations.cache", "doctrine_cache.providers.doctrine.orm.default_metadata_cache", "doctrine_cache.provider
s.doctrine.orm.default_result_cache", "doctrine_cache.providers.doctrine.orm.default_query_cache".
Does anybody know what to do?
Hey Dariusz!
Hmm. So, in Symfony 4, we take advantage of a lot of autowiring, which is really great, except that if you try to use some older code on Symfony 4, some things will need to change to get everything working :). If you've copied the code from this project into a Symfony 4 project (including copying the services.yml file into services.yaml) and you are getting this error, then the cause is probably that you need to remove these lines from your new services.yaml file: https://github.com/symfony/...
If you remove those lines, then you are effectively using the "Symfony 3" coding style inside a Symfony 4 project. If you're serious about learning Symfony 4, I'd definitely recommend checking into the new autowiring stuff - we cover it all in our Symfony 4 series. If you just want to learn more about the specific topics in *this* tutorial, then I might recommend just coding through this tutorial using the code download on this page (so, in Symfony 3). Both options are fine - it just depends on what's more important to you and how much you want to learn the new Symfony 4 stuff versus the actual content in this tutorial :).
Cheers!
Is there anything inherently wrong in this code. I ask because after running for 18 hours it has set 20 SLUGS..... Note I use the unit of work as setting slug to null wouldnt trigger persistance as it defaults to null.
Hey Richard ,
Take a look at my comment here: https://knpuniversity.com/s...
The main idea is do not use Doctrine migrations for such a big and complex tasks like populating slugs in production where you have a lot of entities. Use one-time Symfony commands for it.
Cheers!
This would not work for me until I set "nullable=true" on the $slug field in Genus entity. Since it wasn't working I was just going to allow it to be null and then manually fix things just to keep going. Once I did so then all worked without further manual intervention. Strange!
Ah, strange indeed! We'll have to see if anyone has a similar issue as you in the future :).
Hey guys,
I dont understand why I can't install the stof bundle since I started with the course code. This is what I get from the terminal :
- Installation request for symfony/symfony (locked at v3.1.4, required as 3.1.*) -> satisfiable by symfony/symfony[v3.1.4].
Any clue?
thx
I figure out a way to fix the problem. I just installed the 1.2 version by running composer require stof/doctrine-extensions-bundle ~1.2
It may help others ;)
Helped me. Thanks!
Hey ugo .p!
Ah, thanks for the note! Yea, it looks like the latest version of the bundle doesn't support the version of Symfony we use in this tutorial (even though it would work just fine, actually). I'll add an issue on our end to add a note to help others :).
Cheers!
"Houston: no signs of life"
Start the conversation!