Chapters
41 Chapters
|
4:45:40
|
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!
36.
Form Events & Dynamic ChoiceType choices
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": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.2
"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-paginator-bundle": "^2.7", // v2.8.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
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.1
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.1.6
"symfony/cache": "^3.3|^4.0", // v4.1.6
"symfony/console": "^4.0", // v4.1.6
"symfony/flex": "^1.0", // v1.21.6
"symfony/form": "^4.0", // v4.1.6
"symfony/framework-bundle": "^4.0", // v4.1.6
"symfony/property-access": "^3.3|^4.0", // v4.1.6
"symfony/property-info": "^3.3|^4.0", // v4.1.6
"symfony/security-bundle": "^4.0", // v4.1.6
"symfony/serializer": "^3.3|^4.0", // v4.1.6
"symfony/twig-bundle": "^4.0", // v4.1.6
"symfony/validator": "^4.0", // v4.1.6
"symfony/web-server-bundle": "^4.0", // v4.1.6
"symfony/yaml": "^4.0", // v4.1.6
"twig/extensions": "^1.5" // v1.5.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.1.6
"symfony/dotenv": "^4.0", // v4.1.6
"symfony/maker-bundle": "^1.0", // v1.8.0
"symfony/monolog-bundle": "^3.0", // v3.3.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.1.6
"symfony/stopwatch": "^3.3|^4.0", // v4.1.6
"symfony/var-dumper": "^3.3|^4.0", // v4.1.6
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.1.6
}
}
11 Comments
<blockquote>Expected argument of type "App\Entity\User or null", "string" given.</blockquote>
Hello,
I have this error when i try to update the page with the location, i checked the User entity but i could'not
figure it out ! Any help would be much appreciated !
<b>Here is code for User entity:</b>
Hey Raed,
Difficult to say, better to look at the error stacktrace. I suppose this error is not related to the code you pasted. The problem with that error is that somewhere in your code you're passing a variable to a method that is string instead of "App\Entity\User" object. It would be good to know the exact place, then you would be able to debug that string and see the exact value and figure out why it's so.
Cheers!
Thanks victor for your help ! Its working now, i think this is due a bug in my IDE, i just updated the composer and
it's working, thanks again
Hey Raed,
Woohoo! Thanks for your feedback about getting it working :)
Cheers!
How can I save builder EntityType field with multiple selected options to the database (I use mysql 5.7) and when displaying edit form the "select multiple" field to have those options highlighted (with selected attribute)? I load a list of products via 'class' but on after selecting something and hit save i get error:
"<b>Unable to transform value for property path "licensed_products": Expected a Doctrine\Common\Collections\Collection object.</b>"
This is the code from my builder:
`
->add('licensed_products', EntityType::class,[
])`
licensed_products is a string currently.
Hey Nikolay S.
Sorry for the slow reply :). So, is the licensed_products property on your entity a relation field (e.g. OneToMany or ManyToMany)? If so, did you remember to initialize the property to an ArrayCollection in the entity's constructor? For example:
Let me know if that's the problem :). If not, if you could share your entity code, that might help!
Cheers!
I have a problem when refresh. The thing is:
When I click edit and the form appear all the saved data is shown. If I edit any field and refresh the page the data i've provided is displayed, but after force refresh the original saved data is displayed from the database. Is this an issue or it's handled by cache?
Hey Nikolay S.
That's odd, makes me thinkg that the data didn't save after edit. Could you try it again but before doing a hard refresh, check the data in the DB and corroborate that it indeed saved?
Cheers!
You didn't understand me right. The data is saving, but if a edit is made on the form but the save button is not clicked, after refresh the new data is shown. If I force refresh the page it shows the original data from the database.
Ahh I get it now and I would say that it's not an expected or common behavior. It does not happen in my browser so it might be your browser's cache our maybe an addon of it
Ah thanks, I had forgot it, so I recreated the entities via make:entity and made the relations and now everything works fine.
"Houston: no signs of life"
Start the conversation!