Chapters
29 Chapters
|
1:34:37
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: >=5.3.3
Subscribe to download the code!Compatible PHP versions: >=5.3.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
08.
Doctrine Extensions: Sluggable and Timestampable
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": ">=5.3.3",
"symfony/symfony": "~2.4", // v2.4.2
"doctrine/orm": "~2.2,>=2.2.3", // v2.4.2
"doctrine/doctrine-bundle": "~1.2", // v1.2.0
"twig/extensions": "~1.0", // v1.0.1
"symfony/assetic-bundle": "~2.3", // v2.3.0
"symfony/swiftmailer-bundle": "~2.3", // v2.3.5
"symfony/monolog-bundle": "~2.4", // v2.5.0
"sensio/distribution-bundle": "~2.3", // v2.3.4
"sensio/framework-extra-bundle": "~3.0", // v3.0.0
"sensio/generator-bundle": "~2.3", // v2.3.4
"incenteev/composer-parameter-handler": "~2.0", // v2.1.0
"doctrine/doctrine-fixtures-bundle": "~2.2.0", // v2.2.0
"ircmaxell/password-compat": "~1.0.3", // 1.0.3
"phpunit/phpunit": "~4.1", // 4.1.0
"stof/doctrine-extensions-bundle": "~1.1.0" // v1.1.0
}
}
9 Comments
Ryan thank you again for amazing video. Just wanted to add a "pro-tip". In the video you take shortcut and recreate all the schema when adding `slug`. In real-life scenarios most of the time slug will have to be added to already existing database and thus dropping and recreating schema wouldn't be an option. There's few good examples and proper explanation of how to add slug to existing database in this thread http://stackoverflow.com/qu...
Yo Dimitry K!
Good pro tip indeed! Life is easy with migrations if you haven't deployed yet... not so easy once you *have* deployed.
For data migrations like this that can't be easily accomplished by writing some SQL, we here at KnpU typically write custom, single-use console commands. That's a nice way to get access to Symfony's normal tools (like the EntityManager). We also always make sure to write them in a way where we can restart them if something explodes (because often with data migrations, you are handling a LOT of data, and it's always possible something will go wrong). For example, in this case, we would only try to set the slug on records that don't already have a slug (so that if we restart the command, it doesn't start way back at the beginning).
Glad you added the comment - this data migration stuff is something we handle all the time in the real world!
Cheers!
Hey thanks for the great content!
I just installed added the Blameable to my entities and I am finding that it doesnt work when I try to load data using fixtures, any idea why this is?
Hey Shaun,
Did you follow this instruction: https://github.com/Atlantic... ? Also, StofDoctrineExtensionsBundle do not enable any behavior by default, you need to enable it manually in its bundle configuration in order to use it. And yeah, don't forget to clear the cache just in case ;)
Cheers!
Thanks for your reply Victor, yes I have enabled the behaviour in config/packages/stof_doctrine_extensions.yaml
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
blameable: true
timestampable: true
I also cleared the cache however I still get the same error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'created_by' cannot be null
I am wondering if there is an active 'user' for blameable to set when a data fixture file is being run?
Hey Shaun,
I think I know the problem: this behavior sets up created_by to the *current* user, but since you're in console - there's no current user. For your fixtures, you need to manually set up the proper user. Maybe there's a smarter solution, but I don't know if it exists :)
Cheers!
Hi, Ryan!
What about KnpLabs/DoctrineBehaviors bundle? It seems also a very popular bundle that looks like StofDoctrineExtensionsBundle with similar features. Do you use it? What bundle do you like more to use in your projects?
Thanks!
Hey!
Actually, I don't use this - and I somehow haven't even really seen it yet (unfortunately, there is an ocean between me and the main Knp office, so I can miss things)! But I really like it - in many cases, the functionality that's similar to StofDoctrineExtensionsBundle looks easier to implement - for example Sluggable. I'd like to try this and tell more people about it.
Thanks!
Yes, it's a bit simple for me too. And it has less magic than in StofDoctrineExtensionsBundle :)
"Houston: no signs of life"
Start the conversation!