1
填寫使用PostType表上DB一列我有以下情況: 我有兩個值需要兩個下拉列表存儲在同一個數據庫科拉姆。我的問題是如何來解決這一問題上我buildForm方法以及對html.twig? 我想感謝大家的幫助。 這裏是我的代碼:使用多個下拉列表中的Symfony 3
實體
* @var string
*
* @ORM\Column(name="Diningroom", type="text")
*/
private $diningroom;
/**
* @var string
*
* @ORM\Column(name="Kitchen", type="text")
*/
private $kitchen;
/**
* @var string
*
* @ORM\Column(name="Office", type="text")
*/
private $office;
/**
* @var string
*
* @ORM\Column(name="BedRoom", type="text")
*/
private $bedroom;
buildForm
->add('firstName')
->add('lastName')
->add('email')
->add('telephone')
->add('county')
->add('city')
->add('street')
->add('postcode')
->add('floor', 'entity')
->add('elevator', 'entity')
->add('diningroom')
->add('kitchen')
->add('office')
->add('bedroom')
->add('bathrooms')
->add('boxes')
->add('message')
->add('packing')
->add('personrequired')
->add('submit', SubmitType::class, array(
'label' => 'Get Quotation'
// 'class' => 'btn btn-danger pull right'
))
控制器
public function createAction(Request $request)
{
//create a new post
$removalPost = new Post();
$form = $this->createForm(PostType::class, $removalPost, [
'action' => $request->getUri()
]);
$form->handleRequest($request);
if($form->isValid()){
$em = $this->getDoctrine()->getManager();
$removalPost->setAuthor($this->getUser());
$removalPost->setDate(new \DateTime());
$em->persist($removalPost);
$em->flush();
return $this->redirect($this->generateUrl('RemovalsUK_view',
['id' => $removalPost->getId()]));
}
return $this->render('RemovalsUKBundle:Post:create.html.twig', array
('form' => $form->createView()
));
}
我的HTML
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Table</label>
<select class="form-control required" name="kitchen_table" id="kitchen_table">
<option value="" selected>Quantity</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Seat</label>
<select class="form-control required" name="kitchen_seat" id="kitchen_seat">
<option value="" selected>Quantity</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
</div>
我想要做的就是比如說是插入到廚房列從表和座椅 我將不勝感激任何任何值(數量)對此事進行排序。由於
謝謝,我會嘗試你的解決方案,是的,我會確保我的表格將適合領域,謝謝。 – prezequias