0
我有一個簡單的表格,其中包含一些(< 10)行的3列。使用數據庫中的數據創建Symfony/Twig表格
表:
/**
* @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
}
我有用於示出在預填充形式1行一個工作碼。
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')
;
}
我怎樣才能得到一個形式,從如果表中的所有行不「id」是給定的?
開始與形式的集合:http://symfony.com/doc/current/form/form_collections.html – Cerad
如果我理解正確的,你要編輯的所有PropertyAdditionCostFrequency在同一時間?或者你想要10個表單,每行一個? – goto
@goto是的,我想要以一種形式同時編輯所有行 – bob