Answer the question
In order to leave comments, you need to log in
Do I need to use Symfony forms?
I am learning Symfony Forms. In theory, everything sounds nice and simple. However, in reality, problems arise with a form with already three fields, if one field depends on the other. For example, there are entities City - District - Metro:
class City
{
/**
* @ORM\OneToMany(targetEntity="App\Entity\District", mappedBy="city")
*/
private $districts;
}
class District
{
/**
* @ORM\ManyToOne(targetEntity="App\Entity\City", inversedBy="districts")
* @ORM\JoinColumn(nullable=false)
*/
private $city;
/**
* @ORM\OneToMany(targetEntity="App\Entity\MetroStation", mappedBy="district")
*/
private $metroStations;
}
class MetroStation
{
/**
* @ORM\ManyToOne(targetEntity="App\Entity\District", inversedBy="metroStations")
* @ORM\JoinColumn(nullable=false)
*/
private $district;
}
Answer the question
In order to leave comments, you need to log in
It is not needed in symfony projects: frontend is usually separated into separate applications, and request objects are created even before controller actions.
It usually works like this:
1) The front is a separate js-framework that sends a Rest request
2) The controller at the DTO level, using ParamConverter and Validations, takes values or gives a beat to the front.
3) The value goes to the service, where some logic goes and a response is returned through some kind of json=normalizer.
___
Ps get used to the fact that in large Symfony projects this is not used at all:
* @ORM\ManyToOne(targetEntity="App\Entity\City", inversedBy="districts")
* @ORM\JoinColumn(nullable=false )
Doctrine links do not always work adequately and quickly, so they usually make a composite key for 2-3 columns and dependencies are pulled from the repository by a separate request.
The topic is not so old that I would also like to ask. A similar situation occurs. Before creating an object (that is, not editing a saved entity), I will not find how to process the form. There is a User object, it has nested dependencies.
$user = $this->getUser();
// Какое то значение
$client = $user->getClient()->getClientSomeData();
// Допустим теги, описания, которое являются ArrayCollection вообще тьма
$clientTags = $user->getClient()->getTags()->getTag()->getName();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question