I am busy developping a Symfony 3 app.
I need to know if it is possible to have an action which is served by 2 routes :
- one with 1 parameter
- one with 2 parameters
In the first case, it would be for creating a new entity which is associated to the given entity. In the second case, it would be to edit an existing and given entity, which is associated to another given entity.
If that's not clear, here my example:
/**
* @Route("/admin/instances/{group}/reunions/nouveau", requirements={"group": "\d+"})
* @Route("/admin/instances/{group}/reunions/{reunion}/modifier", requirements={"reunion": "\d+"})
* @Method({"GET", "POST"})
*
* @param Request $request
* @param Group $group
* @param Reunion $reunion
*
* @return Response
*/
public function newEditAction(Request $request, Group $group, Reunion $reunion = null)
{
if (!$reunion) {
// we know we are busy with a creation
}
}
Although, with this, the $reunion
is never null
unless the table which contains the entities is empty.
Because both entities Group and Reunion are related to each other (see relation below), it seems Symfony automatically searches for the first Reunion entity that is associated with the given Group. Any idea why?
Reunion.php
/**
* @var \AppBundle\Entity\Group
*
* @ORM\ManyToOne(targetEntity="Group", inversedBy="reunions")
* @ORM\JoinColumn(name="reunion_group_id", referencedColumnName="group_id")
*/
private $group;
Thank you for your help.