Symfony2 country field multiple choices
What if you need to allow user to select more than 1 country ?
Pretty simple, using the country field type. In the entity we do:
/**
* @var string
*
* @ORM\Column(name="country", type="simple_array", length=255, nullable=true)
*/
private $country;
So our type is set to array. Doctrine will take care of serialize/unserialize, so the getter will return an array easy to use.
If you use sonata, you can add this form type to have multiple choices:
->add('country','country',array('multiple'=>true));
Done! ;)
Written by pleone
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#