I have a simple table with 3 columns with some (<10) rows.
Table:
/**
* @ORM\Entity
* @ORM\Table(name="property_addition_cost_frequency")
*/
class PropertyAdditionCostFrequency
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/private $id;
/**
* @ORM\Column(type="string")
*/
private $label;
/**
* @ORM\Column(type="string")
*/
private $group;
/**
* @ORM\Column(type="string")
*/
private $active;
//all getters and setters
}
I have a working code for showing 1 row in a prefilled form.
AdminCoreDataController.php
/**
* @Route("/core_data/{id}", defaults={"id" = 1}, name="admin_core_data")
*/
public function showCoreDataListAction( Request $request, PropertyAdditionCostFrequency $propertyAdditionCostFrequency )
{
$form = $this->createForm( PropertyAdditionCostFrequencyForm::class, $propertyAdditionCostFrequency);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$propertyAdditionCostFrequency = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->persist($propertyAdditionCostFrequency);
$em->flush();
$this->addFlash('success', 'successfully changed the data');
return $this->redirectToRoute('admin_property_list');
}
return $this->render('logged_in/content/admin/core_data/core_data.html.twig', [
'propertyCostFrequencyForm' => $form->createView()
]);
}
core_data.html.twig
{{ form_start(propertyCostFrequencyForm) }}
{{ form_widget(propertyCostFrequencyForm.label) }}
{{ form_widget(propertyCostFrequencyForm.active) }}
<button type="submit">send</button>
{{ form_end(propertyCostFrequencyForm) }}
PropertyAdditionCostFrequencyForm.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add( 'label' )
->add( 'active' )
;
}
How can I get a form with all rows from the table if no "id" is given?