In a Symfony2/Doctrine project, I have an Entity called Developer
including those fields in particular:
1. firstName
2. lastName
3. machineName
The form to create a Developer item only shows firstName and lastName fields. I'd like the machineName to be automatically generated when the user creates a Developer item, based on the two other fields.
For instance, John Doe
would give john_doe
and Jérémy Arçouille
would give jeremy_arcouille
.
So my questions are:
- Is there a general best practice for this (pretty common) case?
- Do I have to code something from my own or is it something pretty standard?
- If (2 == true) what would be the best place (services? utils?) to put that trunk of code?
- Should I rather call this portion of code from the controller or from the entity?
Note: because it would be quite a portion of code, and I'd like it to be reusable, I don't want to put into a prePersist lifecycle callback
I once developed a full solution for this problem and it worked well, but was really lame and spaghetti-esque, so I'd rather make something more in the proper Symfony2 way by now.
Thanks for any help.