![]() ![]() ![]() FunctionĬhange all keys in an array to lowercase or uppercase So if you are deciding between JSON vs Entity, add EAV to the race.Here is an alphabetical list of PHP’s built-in array functions. After some IRC conversations, reading and this I will probably go with EAV. I know I wrote no entity, but I didn't made up my mind. PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "NULL" while trying to traverse pathĪnd then in the twig template you can do this: Īs for the JSON or Entity. In order for symfony to map/populate values in edit mode the property must have it's key defined. Because we used json_array as a type, symfony will handle json_encode/json_decode thing. 'property_path'=>'questionnaire'Īnd symfony will handle the rest. Public function buildForm(FormBuilderInterface $builder, array $options) Next, in the form builder use the "property_path"! It's that simple. In the entity class with this json_array, define all needed keys like so: /** I've actually didn't found a lot on this particular problem, so in case you need something similar, here it is. Bounty didn't helped to get it faster, but hey, there is a solution! o) This is my first date with symfony so any help/tips appreciate.Īfter few days I found the answer for my own question. I would like to avoid creating entity for that with each question as a property (not sure if it's a right choice, but considering everything I believe it's the best one). Questionnaire itself will have many ChoiceType fields, a CollectionType with "Add more row" and so on and it will have lots of questions. This "feels" ok, but I'm not sure how to later handle this in "Edit" form (from docs I think with this ). Create all fields that are in Questionnaire with the "mapped=>false" and then set those submitted values as an associative array to $questionnaire. So I was thinking Data Transformers or simply creating an array on submit without this Transformer thing. But if I'm wrong about this and I should go with CollectionType and there is some magic way please tell me. So currently my choices I see are: CollectionType or Data Transformers.įrom what I see, CollectionType will not work, as it's only work with numeric arrays where we have field with some JS "Add another row" or something. ![]() For symfony masters it's obvious I know o) So this is great.īut now, I have a bit of problem with creating a form with the symfony builder.įirst I thought I could try something like this: $builder->add('questionnaire') I understand that Symfony will take care of json_encode/json_decode thing. So currently in my User entity I have this: /** Those questions can change in the future, there are currently ~30 questions so I don't want to store it as an entity. I was thinking to store them in database as a json in a text field. I also need to store answers from a questionnaire. I need user profile that will have basic info like name, email, phone etc. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |