I want to have a form where I can add new fields (columns) in an specific entity. Is there a function for this?

Kind regards

Sedir Mohammed

1 Answers

medunes On

Adding a whole column to the table through an HTML form is a weird use case. If you want to stick to the ORM way of managing the persisted data, you'll have to dynamically add properties to existing entities, which might be a sign of bad schema design.

What I would guess you probably need is an automated way to add this column to your Entity. In such a case I would use the maker bundle.

Supposing that your Entity is called Employee, all you have to do is to type in the following command:

bin/console make:entity

When you'll be asked for the Entity name, enter Employee. The interpreter will tell you that this entity exists and if you want to extend it with news fields, and there you go.