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!
27.
Collection Filtering: The Easy Way
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 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
}
}
8 Comments
I am struggling with my scenario:
Imagine you have a Teacher, Subject, Room entities.
Teacher can teach many Subjects
Teacher can teach in many Rooms
Subject can be tough in many Rooms so rooms and subjects are linked but 1 Room can have 1 subject. OneToMany
Now imagine I want to create a Teacher so I will select Subjects(teacherSubjects = arrayCollection)
After subjects have been added I can pre-filter Rooms available and store them (teacherRooms = arrayCollection)
Now I will remove subject from the removeSubject and click save.
I want automatically remove all associated Rooms from teacherRooms.
I tried to do it inside removeSubject but when form is submitted it is not even triggering this method same is happening when I am adding new subject method addSubject is not hit.
I know I could probably solve this if I decide to set this field as not mapped but I would assume this can be done automatically.
Hey Peter K.
Yeah you have a tricky situation. As I know this cannot be done automatically because this fields are not synced, to sync them you can create Doctrine entity listener, and listen to PreUpdate and probable PrePersist and check your list changes and sync lists.
Hope this will help. Cheers!
I decided to go the unmapped field way
Awesome! This is one of real super powers of Symfony! You choose the way you want to code =)
Cheers!
Typo: "
Oh my, a Missing inversedBt" should be inverseBy
Hey Michael,
Ah, great catch! Thank you for pointing it out! It was fixed in https://github.com/knpunive...
Cheers!
Great, I didn't know the course content was available on gitub. I'm not familiar with the github [[[ code('..') ]]], how is that set up? (Searching for 'github code' gets everything!). Is it a gist? Or something you tag in the code somehow?
Hey Michael,
Yeah, that's a little-known fact. You may even notice a pencil icon on course chapter pages in the right top corner of scripts. If you press it - it will move you to the corresponding page on GitHub.
About that [[[ code('..') ]]] syntax - it's our own, we implemented it internally. It is dynamically replaced with actual code blocks, but we use an internal tool that helps to display specific code on different steps. It helps us to show the *actual* code on chapter pages - no more outdated static code blocks. And that's the one of our coolest features on SymfonyCasts. :)
Cheers!
"Houston: no signs of life"
Start the conversation!