I am working on a web application in Symfony2. I came to the point where I needed a few tips / explanations from another advanced Symfony.
I have a part of my database that is configured as follows:
I have maps that belong to a set of map attributes and consist of map values.
I have a set of map attributes that have many attributes, a map attribute can belong to many map attributes (obviously, this relationship is many, many).
Then, depending on the map attribute, the attribute has an attribute value, for example, text has text_value of type varchar, and boolean has value_boolean of type boolean.
Can you imagine, when you create a form for creating a new map, the form should generate input fields depending on the attribute of the map to which it belongs, and depending on the attributes that belong to the set attribute?
So here is my question; There is a way to dynamically generate input fields in a form depending on the object selected by the user. I read about events, but I'm not sure that they satisfy my needs.
This is the code for my entities (I removed Getters and Setters for a simpler view):
map:
class card { private $id; private $cardLabel; protected $card_project; protected $cardAttrSet; protected $card_values; private $users; public function __construct() { $this->card_values = new ArrayCollection(); $this->users = new ArrayCollection(); } }
Map Attribute:
class cardAttribute { private $id; private $name; private $type; }
Map Attributes Set
class cardAttributeSet { public $id; private $casLabel; private $cas_cards; private $attributes; public function __construct() { $this->cas_cards = new ArrayCollection(); $this->attributes = new ArrayCollection(); } }
Map Attribute Value
/** * cardAttrValue * * @ORM\Table() * @ORM\Entity(repositoryClass="clientsBundle\Entity\cardAttrValueRepository") * @UniqueEntity( * fields={"valueText"} * ) */ class cardAttrValue { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="value_text", type="string", length=255, nullable=true) */ private $valueText; /** * @var string * * @ORM\Column(name="value_varchar", type="string", length=255, nullable=true) */ private $valueVarchar; /** * @var integer * * @ORM\Column(name="value_int", type="integer", nullable=true, nullable=true) */ private $valueInt; /** * @var boolean * * @ORM\Column(name="value_boolean", type="boolean", nullable=true, nullable=true) */ private $valueBoolean; /** * @ORM\ManyToOne(targetEntity="card", inversedBy="card_values") * @ORM\JoinColumn(name="card_id", referencedColumnName="id") **/ private $card; /** * @ORM\ManyToOne(targetEntity="cardAttribute") * @ORM\JoinColumn(name="cardAttributes_id", referencedColumnName="id") **/ private $cardAttribute; }