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!
15.
Adding Extra "Unmapped" Fields
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
}
}
16 Comments
for me, unless I make plainPassword RepeatedType, it doesn't work.
for those who wonder how,
`->add('plainPassword', RepeatedType::class, array(
Hey Remus M.
What's not working for you, the
mapped => falseoption?data.plainPassword
This value should not be blank.
Caused by
ConstraintViolation
LE: sorry about that, i still had plainPassword field from a previous tutorial :)
For those who may be as confused as I was about this, you can use RepeatedType to render two password fields. Symfony will check for you that both values match. Read more about it on the docs https://symfony.com/doc/cur...
Hope this helps :)
Hey Tobias,
Thank you for sharing it with others! Yeah, if you want to double sure users didn't misprint his password - you can use RepeatedType along with PasswordType.
Cheers!
Hi,
I was taking a look at the 5.4 docs after watching this video and noticed `PasswordAuthenticatedUserInterface` being implemented to User on one of the examples. Would this be the equivalent of doing the plainPassword technique shown in this vid on newer versions of Symfony?
Hey Kevin
Yes, the main idea here is to avoid adding a property on the User object that will hold the value of plainPassword. So, in this video Ryan teaches how you can add fields to a form that are not mapped to an entity
Cheers!
why don't we just handle the encoding within the setPassword method in the entity ? Doesn't it make more sense to have it one place rather having encoding code duplicated in multiple places?
Hey Abdul,
The problem is that PasswordEncoder - that's a *service*, and you don't have access to services from your entities because entities are just simple data objects. That's why we have to pass the entity through some code that will generate the correct password using that service and set it on the entity.
I hope this is clearer for you now.
Cheers!
Hi, how would I transform an unmapped Datetime field into a DateTime object from an array? thank you.
Hey Benoit L.
Have you tried setting up the DataType of the unmapped field to a Symfony "DateTimeType"? https://symfony.com/doc/cur...
Cheers!
It's great the unmmaped field but I have a problem on my side. The password on the user entity is required. So when I want to register a user I don't pass the isValid method because the password is not set (only the plaintext password), and we're supposed to set the password after validation of the form.
So should I make the password nullable in the database ?
Hi,
If you use symfony 4.3
Use validation groups to do validation because of this new feature : https://symfony.com/blog/ne...
https://symfony.com/doc/cur...
Hey ionik!
you're right - this issue is related. We've temporarily disabled this new automatic validation feature on new Symfony 4.3 projects - you can still enable it in validator.yaml, but it's no longer enabled by default: https://github.com/symfony/...
If you started a Symfony 4.3 project during the first few weeks of June, you will have this setting enabled. If it's causing issues, you can disable the "auto_mapping" key in validator.yaml. We're working to add a few more features to make it a bit more flexible before auto-enabling it in the future :).
Cheers!
Thanks for your reply of explanation ;)
Hey Martin,
You need to add validation constraints to the plainPassword instead of hashed password, because you work with plainPassword in the form. And then you will not need to make the password field nullable in the DB, you still can keep it required, but then it's your job to properly set the password field when user sent you a plainPassword and the form is valid.
Cheers!
"Houston: no signs of life"
Start the conversation!