0

I am using Symfony 6 and created an entity for global options and so the sql table has only 3 columns : name, label and value

In order to store global info about my app. Like this.

id name label value
1 maintenance Set the app in maintenance 0
2 allow_comments Allow comments for products 1

How can I make a form which contains every elements of the table ?

I would like the result to be like this : Expected form result

Thanks

1
  • You are asking a very broad question and I even wonder how you have a web application at all to configure if you can't do a crud for such a simple entity. Despite being simple it involves too much stuff and you should learn from symfony doc and come back with more specific questions Commented Apr 24, 2022 at 21:58

1 Answer 1

1

As you have a table (so it's an entity I guess) CollectionType is a way to go.

use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
// ...

$builder->add('emails', CollectionType::class, [
    // each entry in the array will be an "email" field
    'entry_type' => EmailType::class,
    // these options are passed to each "email" type
    'entry_options' => [
        'attr' => ['class' => 'email-box'],
    ],
]);

As the entry_type you can just pass EntityType.

Ref: https://symfony.com/doc/current/reference/forms/types/collection.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for taking the time to read my question. Indeed I have an entity GlobalOption. I couldn't understand how I can apply your example to my needs though. I know this is a simple crud operation, but I am used to process only one row of the table.. Thanks anyway !
@lccsc as the entry_type you can pass EntityType:class. Then in the entry_options you can configure it. Ref: symfony.com/doc/current/reference/forms/types/entity.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.