An aticle has several variables. A title, a date, visibility and a category. If i render a form with symfony, i want to preselect a category in the dropdownlist. In the controller i have a function :
/**
* @return Response
* @route ("/admin/add/{idartikeltype}",name="addbytype")
*/
public function addByType(Request $request, $idartikeltype)
{
$form = $this->createForm(ArtikelType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$item = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->persist($item);
$em->flush();
return $this->redirectToRoute('lookup');
}
return $this->render('backend/add.html.twig', array('form'=>$form->createView(),));
}
The slug idartikeltype, an integer, contains the id of the category. How must i preselect the correct category in a blanc form?