I have an entity ,there is a array type attribute:productKey.I try to add a choice typy to the form to show the productKeys,I wrote codes:
1.my formType:
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('heading','text',array('label'=>'title'))
->add('productKey','choice',array(
'required'=>TRUE,
'label'=>'choose your product',
));
}
2.In my Product entity the productKey is defined:
/**
* @var array $productKey
*
* @ORM\Column(name="productKey", type="array",nullable=true)
*/
private $productKey;
3.In my controller:
$entity = new Product();
$productKey = array("1"=>"one","2"=>"two","3"=>"three");
$entity ->setProductKey($productKey);
$formType = new TicketType($productKey);
$form = $this->createForm($formType,$entity);
return array(
'form'=>$form->createView(),
'entity'=>$entity
);
when I run my project ,the value of productKey can not be listed ! it just appear an empty select chice input. How can i solve it?