UPDATE: I just to precise that I’m new to Symfony2 and generally with frameworks. I would like to clarify my question: I wish a big form with many fields and the label of each field is from a second DB. It would take 30minutes in pure PHP without a framework, but how can I do it with Sf2?
I’m having an issue to display in one form multiple times the same entity.
Here is the context:
I have a parking lot with multiple parking places. To manage at best the parking lot,it is decided to give a priority order to each parking place to be occuped.
The manager of the parking lot can change the priorities at any moment but a historical must be in place.
The parking places are already declared and the manager can’t edit them.
So to do so, I have created to entities: ParkingPlaces and Historical. Historical as ManyToOne ParkingPlaces.
I wish that for each parking place label, there is a field to enter the occupation priority in one form.
The entities are declared as such:
class Historical
{
/**
* @ORM\Column(name="date", type="datetime")
*/
private date;
/**
* @ORM\ManyToOne(targetEntity="ParkingPlace")
* @ORM\JoinColumn(name="parkingplace_id", referencedColumnName="id")
*/
private parkingPlace;
/**
* @ORM\Column(name="priority", type="integer")
*/
private priority;
}
class ParkingPlace
{
/**
* @ORM\Column(name="name", type="string", lenght=255)
*/
private name;
/**
* @ORM\OneToMany(targetEntity="Historical", mappedBy="parkingPlace")
*/
private historical;
}
And that is the render I wish:
<form>
<fieldset>
<legend>Parking A1</legend>
<input name="priority" type="number" />
</fieldset>
<fieldset>
<legend>Parking A2</legend>
<input name="priority" type="number" />
</fieldset>
<fieldset>
<legend>Parking A3</legend>
<input name="priority" type="number" />
</fieldset>
<fieldset>
<legend>Parking A4</legend>
<input name="priority" type="number" />
</fieldset>
...
</form>
I have spent many hours on it, but I didn’t any solution. I have tried many solution on Stack but none answers my problem.
I managed to answer the question. I changed the DB architecture and used a ‘Collection’ field in my form.
I leave here the entire code. I hope it will help other people.
History Entity
ParkingPlace Entity
ParkingPlacePriority Entity
History Controller
History FormType
ParkingPlacePriority FormType
History new entity form template