I create a new object and bind it to a form. The user fills out the form and goes to a preview page. I store the user responses in the session.
The problem crops up when I try to reload the object from the session when the user goes back to edit the form. I get :
Error: the Entities passed to the choice field must be managed.
Anyone have an idea of where i might be going wrong? Heres the code for the controllers.
public function previewdealAction(Request $request){
$session = $this->getRequest()->getSession();
$coupon = $session->get('coupon');
$form = $this->createForm(new CouponType(), $coupon);
if ($request->getMethod() == 'POST') {
//bind the posted form values
$form->bindRequest($request);
//once a valid form is submitted ...
if ($form->isValid()){
//Proceed to Previewing deal
$file = $coupon->getImage();
$file->upload();
$session->set('coupon', $coupon);
$repository = $this->getDoctrine()
->getRepository('FrontendUserBundle:Coupon');
$coupons = $repository->findAll();
return $this->render('FrontendHomeBundle:Merchant:dealpreview.html.twig', array('coupon'=>$coupon, 'coupons'=>$coupons));
}
}
}
public function builddealAction(Request $request){
$em = $this->get('doctrine')->getEntityManager();
$user = $this->container->get('security.context')->getToken()->getUser();
//check for a coupon session variable
$session = $this->getRequest()->getSession();
$coupon = $session->get('coupon');
//If coupon is not set
if($coupon == NULL){
$coupon = new Coupon();
$date = new \DateTime(date("Y-m-d H:i:s"));
$coupon->setStartdate($date);
$coupon->setPosterid($user);
$session->set('coupon', $coupon);
}
$form = $this->createForm(new CouponType(), $coupon);
return $this->render('FrontendHomeBundle:Merchant:builddeal.html.twig', array(
'form' => $form->createView(),
));
}
--
namespace Frontend\HomeBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class CouponType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options) {
$builder->add('couponname', 'text');
$builder->add('description', 'textarea');
$builder->add('price', 'money', array('currency' => 'USD'));
$builder->add('originalprice', 'money', array('currency' => 'USD'));
$builder->add('maxlimit', 'integer');
$builder->add('maxper', 'integer');
$builder->add('startdate', 'date', array(
'years' => array(2011, 2012, 2013, 2014),
));
$builder->add('duration', 'choice', array(
'choices' => array(
'3' => 3,
'7' => 7,
'14' => 14,
'30' => 30,
'60' => 60,
'90' => 90,
),
'expanded' => false,
'multiple' => false,
));
$builder->add('expirationdate', 'choice', array(
'choices' => array(
'30' => 30,
'60' => 60,
'90' => 90,
'180' => 180,
),
'expanded' => false,
'multiple' => false,
));
$builder->add('tip', 'integer');
$builder->add('salestax', 'choice', array(
'choices' => array(
'included' => 'Sales tax is included and will be remitted BY YOU at the appropriate tax jurisdiction',
'exempt' => 'Sales tax is exempt according to seller\'s tax jurisdiction',
'collected' => 'Sales tax will be collected BY YOU at time of deal redemption',
),
'expanded' => true,
'multiple' => false,
));
$builder->add('signature', 'text');
$builder->add('city', 'entity', array(
'class' => 'Frontend\\UserBundle\\Entity\\Cities',
'expanded' => false,
'multiple' => false,
));
$builder->add('category', 'entity', array(
'class' => 'Frontend\\UserBundle\\Entity\\Category',
'expanded' => false,
'multiple' => false,
));
$builder->add('address', new AddressType());
$builder->add('image', new DocumentType());
$builder->add('maxper', 'choice', array(
'choices' => array(
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 5,
'6' => 6,
'7' => 7,
'8' => 8,
'9' => 9,
'10' => 10,
),
'expanded' => false,
'multiple' => false,
));
}
public function getDefaultOptions(array $options) {
return array(
'data_class' => 'Frontend\UserBundle\Entity\Coupon',
);
}
public function getName()
{
return 'user';
}
}
heres the coupon type class
I was experiencing the same problem - I was retrieving data from a form using getData() and storing in the session. Later on, after a redirect, I was attempting to repopulate another instance of the same form using setData().
I experienced no issues with native fields. However, when my form included an entity I was receiving the same dreaded message "Entities passed to the choice field must be managed".
After some head scratching the issue revealed itself to be pretty straightforward (aren't they all?). After a redirect, the entity has become detached; the solution is simply to re-include the entity into the EntityManager using EntityManager::merge(), thus reinstating the entity as a managed object :)
// an array of form data from session
$entity = $data['my_entity'];
// merge() returns the managed entity
$entity = $this->getDoctrine()->getEntityManager()->merge($entity);
// update the form data array
$data['my_entity'] = $entity;
// Create form with form data
$form = $this->createForm(new MyFormType(), $data);
http://www.doctrine-project.org/api/orm/2.0/doctrine/orm/entitymanager.html
Hope this helps!
It's not relating to solve your specific problem but I'd like to annotate:
I've had the same problem and could solve it by removing 'by_reference' => false which was needless here and the reason for this error.
Had the same problem and used pretty much the answer Daggah supposed, but added a small loop through the array of entities, checking for objects:
if ($this->get('session')->has('filters')) {
$filters = $this->get('session')->get('filters');
foreach ($filters as $key => $filter) {
if (is_object($filter)) {
$filters[$key] = $em->merge($filter);
}
}
$filterForm = $this->createForm(new FilterType(), $filters);
}
Hope this helps someone.
I had the same problem and both answers were very helpful, but my issue involved multidimensional arrays so to keep things dynamic I used a recursive version of jahller's function.
private function manageObjects(&$data_array)
{
foreach ($data_array as $key => &$value)
if (is_object($value))
$data_array[$key] = $this->container->get('doctrine.orm.entity_manager')->merge($value);
else if (is_array($value))
$this->manageObjects($value);
}
Hope this helps someone.
More complex solution basing on prev comments.
Support ArrayCollections and DateTime objects
/**
* Merge objects
* Allow to manage object by doctrine when using stored (eg. in session data values)
* #param $data_array - list of form fields
* #return mixed
*/
public function manageObjects($data_array)
{
foreach ($data_array as $key => $value) {
// for multi choices
if ($value instanceof ArrayCollection) {
$data_array[$key] = $this->manageObjects($value);
}
//ommit dateTime object
elseif ($value instanceof \DateTime) {
}
elseif (is_object($value)) {
$data_array[$key] = $this->getService('doctrine.orm.entity_manager')->merge($value);
}
}
return $data_array;
}
Related
when i submit my form, I have two values to choose from:
WorkPlanningDay and workPlanningHour.
if workplanninghour is specified, we insert a row in the workplanninghour table and vice versa
When I submit a workPlanningHour, I want to prevent doctrine from inserting a workPlanningDay object with null data. I tried to use a $form->remove but without success.
here is my request datas :
{"statuses":[6],"work_planning":1,"work_planning_hour":{"count_jrtt":1,"end_at":"31-12","jrtt":true,"lower_hour_jrtt":35,"nbr_jrtt":24,"start_at":"01-01","upper_hour_jrtt":39},"work_planning_period":0,"working_time_aspect":{"days":["MON","TUE","WED","THU","FRI"],"time":0,"weekly_hours":35}}
here is my form with my EventListener :
class WorkingTimeParametersRESTType extends AbstractType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('work_planning', Field\ChoiceType::class, array(
'property_path' => 'workPlanning',
'required' => true,
'choices' => WorkingTimeParameters::getAllowedWorkPlannings(),
))
->add('work_planning_period', Field\ChoiceType::class, array(
'property_path' => 'workPlanningPeriod',
'required' => false,
'choices' => WorkingTimeParameters::getAllowedWorkPlanningPeriods(),
))
->add('working_time_aspect', WorkingTimeAspectType::class, array(
'property_path' => 'workingTimeAspect',
'required' => true,
'constraints' => array(new Valid())
))
->add('work_planning_hour', WorkPlanningHourType::class, array(
'property_path' => 'workPlanningHour',
'required' => true,
'constraints' => array(new Valid())
))
->add('work_planning_day', WorkPlanningDayType::class, array(
'property_path' => 'workPlanningDay',
'required' => true,
'constraints' => array(new Valid())
))
->add('statuses', Field\CollectionType::class, array(
'entry_type' => CategoryIntegerType::class,
'entry_options' => array(
'category_type' => Category::TYPE_STATUS,
),
'allow_add' => true,
'allow_delete' => true,
'required' => true,
'error_bubbling' => false,
))
->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData'))
->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
/** #var WorkingTimeParameters $contract */
$parameters = $event->getData();
$form = $event->getForm();
// dd($form->has('work_planning_day'));
// Remove useless work planning
if ($parameters->getWorkPlanning() == Contract::WORK_PLANNING_HOUR) {
$parameters->setWorkPlanningDay(null);
$form->remove('work_planning_day');
}
else if ($parameters->getWorkPlanning() == Contract::WORK_PLANNING_DAY) {
$parameters->setWorkPlanningHour(null);
$form->remove('work_planning_hour');
}
else {
dd('rerer');
$form->remove('work_planning_day');
$form->remove('work_planning_hour');
$parameters->setWorkPlanningDay(null);
$parameters->setWorkPlanningHour(null);
$parameters->setWorkPlanningPeriod(null);
}
})
;
}
/**
* #param FormEvent $event
*/
public function onPreSetData(FormEvent $event)
{
$rttParameters = $event->getData();
$form = $event->getForm();
// The company can be set only on creation
if (!$rttParameters || !$rttParameters->getId()) {
$form->add('company', CompanyIntegerType::class, array(
'required' => true,
));
}
}
and here are the requests that doctrine is trying to launch :
INSERT INTO w2d_tm_work_planning_hour (startAt, endAt, jrtt, countJrtt, lowerHourJrtt, upperHourJrtt, nbrJrtt) VALUES ('1970-01-01 00:00:00', '1970-12-31 00:00:00', 1, 1, 35, 39, 24);
UPDATE w2d_tm_work_planning_day SET startAt = NULL, endAt = NULL, nbrDays = NULL, nbrJrtt = NULL WHERE id = 1;
how to do so that doctrine does not launch the second request with the null values ?
Symfony form type are not made to handle different entities depending on a option you selected inside.
This not how Symfony FormType are supposed to be used. This is why the data_class attribute is made for one entity.
You best option is to create two distinct FormType and submit only the one needed depending on what the user selected on frontend. (easy with a little of javascript)
The second advantage of this is you will have much more understandable and maintable code.
I'm trying to make my firsts unit tests and functionnal tests with Symfony3 / PHPunit and I don't find solutions to my problem.
To be simple, I'm trying to Unit Test a form created to manage Users and Groups (provided by FOSUserBundle)
I followed the steps of the Symfony documentation to test my form, and I already solved some issues concerning getExtensions(), etc... to be able to run my test without any error
Here is my UserType.php :
<?php
...
class UserType extends BaseCrudForm
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('username', null, array('label' => 'label.username'))
->add('email', EmailType::class, array(
'label' => 'label.email',
'constraints' => array(
new Email()
)
))
->add('enabled', CheckboxType::class, array('label' => 'label.enabled', 'required' => false))
->add('groups', EntityType::class, array(
'class' => 'Acme\AdminBundle\Entity\Group',
'multiple' => true,
'required' => false,
))
->add('avatarImageFile', FileType::class, array('label' => 'label.avatar', 'required' => false))
;
}
...
}
and my UserTypeTest.php (I left my tests into it) :
<?php
...
class UserTypeTest extends BaseTypeTestCase
{
public function testSubmitValidData()
{
$formData = array(
'username' => 'nathalie_' . time(),
'email' => 'nathalie_' . time() . '#portman.fr',
'enabled' => true,
'plainPassword' => 'pa$$word',
///// SOLUTION 1
'groups' => array(
$this->em->getRepository('AcmeAdminBundle:Group')->find(1)
),
///// SOLUTION 2
'groups' => array(1),
);
$form = $this->factory->create(UserType::class);
$user = User::fromArray($formData);
$form->submit($formData);
$this->assertTrue($form->isSynchronized());
// dump($user, $form->getData());
$this->assertEquals($user, $form->getData()); //Fails
$view = $form->createView();
$children = $view->children;
foreach(array_keys($formData) as $key) {
$this->assertArrayHasKey($key, $children);
}
}
}
Problem :
The assert $this->assertEquals($user, $form->getData()); fails, because of the collection User::groups that is not equal
Solution 1 is not working (see code above)
The collection of $user is ok, but the form data is empty
Solution 2 is not working neither (see code above)
The form data is ok, but the $user collection is instantiated with a simple array(1) (sees logic)
Question
How could I instanciate correctly my object User and my form at the same time with the same informations (as it's described in the Symfony documentation a linked in top of this topic) ?
Note: as I said I'm a newbie with Unit Tests, so don't hesitate to tell me if I miss the point
Edit
Here is the fromArray function, implemented as a Trait in the User entity :
<?php
namespace Acme\AdminBundle\Traits;
use Doctrine\Common\Util\Inflector;
trait FromArrayTrait
{
/**
* #param array $data
* #return self
*/
public static function fromArray(array $data)
{
$object = new self;
foreach ($data as $key => $value) {
$method = 'set' . Inflector::classify($key);
if (method_exists($object, $method)) {
call_user_func(array($object, $method), $value);
}
}
return $object;
}
}
I have a symfony2 main form, with a field what is a collection type of an other field, like a Product entity with multiple Tag, but these tag has a unique hash.
There is an eventListener attached to the main form. If I send a data to the form and I send a Tag along with this unique has, the unique constraint on the class will say, that that field has to be unique. This work good, but in this EventListener I'm search in the DB for this unique field and if it's the right one, I do an assign, I replace the post content with an entity from the DB.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('eventDate', 'datetime',array(
'widget' => 'single_text',
'format' => 'yyyy-MM-dd HH:mm',
'invalid_message' => 'Wrong datetime format. Please use like this: 2015-09-20 14:45:12',
))
->add('eventEnds', 'datetime', array(
'widget' => 'single_text',
'format' => 'yyyy-MM-dd HH:mm',
'invalid_message' => 'Wrong datetime format. Please use like this: 2015-09-20 14:45:12',
))
->add('tag','collection', array(
'type' => new TagType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'property_path' => 'professional',
'label' => false,
'options' => array(
'professional' => true,
),
))
->addEventListener(FormEvents::SUBMIT, [$this, 'submit'])
;
}
public function preSubmit(FormEvent $event)
{
/** #var MainForm $data */
$data = $event->getData();
foreach ($data->getTags() as $tag) {
if ($tag->getId() == null && $tag->getHash()){
$tagDB = $this->entityManager
->getRepository('ApplicationBundle:Tag')
->findOneBy([
'hash' => $professional->getHash(),
]);
if ($tagDB) {
$data->removeTag($tag);
$data->addTag($tagDB);
}
}
}
$event->setData($data);
}
If I dump the $data value after the setData, I see there the entities from the DB, but I still got a Unique validation error and I check in the validator, symfony pass in the original POST content.
Why is it like that and how can I solve this problem?
Should be
->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'submit'])
(PRE_SUBMIT instead of SUBMIT)
Your code should be something like:
public function preSubmit(FormEvent $event)
{
/** #var MainForm $data */
$data = $event->getData();
$num = count($data['tag']);
for ($i=0;$i<$num;$i++) {
$tag = $data['tag'][$i];
if (!isset($tag['id']) && isset($tag['hash'])){
$tagDB = $this->entityManager
->getRepository('ApplicationBundle:Tag')
->findOneBy([
'hash' => $tag['hash'],
]);
if ($tagDB) {
unset($data['tag'][$i]);
$data['tag'][$i] = array (
'id' => $tagDB->getId();
'hash' => $tagDB->getHash();
);
}
}
}
$event->setData($data);
}
Not sure the code is 100% correct as I have not been able to test it, but you get the idea.
In a Symfony 2.7 project,
let's say we have a form composed of 2 fields 'date'(date) and 'group'(entity), both have their own EventListener attached to, for FormEvents::SUBMIT events.
After the first submit, I'd like to add a new field 'travels' to the form and populate it with the result of a query using the two previous fields as criterias.
How to prevent 'travels' entity field from fetching all 'travel' in the DB and populate it manually after the raised events ?
I certainly miss some comprehension, I'm new to Symfony.
I know I can pass data directly in 'choices' option when creating 'travels' in each event but it would make useless DB calls.
I might count the number of registered events (of interest) and create 'travels' field when last event happens but it seems kind of weird...
Is there a clean solution for this case ?
(excuse for English, not my native language)
<?php
namespace MyBundle\Form;
// use directives...
class TravelRequestsWorklistType extends AbstractType {
private $em;
private $travelRepository;
private $searchQueryBuilder;
public function __construct(EntityManager $em) {
$this->em = $em;
$this->travelRepository = $this->em->getRepository(Travel::class);
}
public function buildForm(FormBuilderInterface $builder, array $options) {
$formFactory = $builder->getFormFactory();
$builder
->add('requestedDate', 'date', array(
'widget' => 'single_text',
'input' => 'datetime',
'format' => 'dd/MM/yyyy',
'attr' => array('class' => 'date'),
'data' => null,
'mapped' => false
))
->add('selectedGroup', 'entity', array(
'class' => 'MyBundle\Entity\Group',
'placeholder' => '',
'mapped' => false,
'multiple' => false,
))
->add('search', 'submit');
$builder->get('requestedDate')->addEventListener(FormEvents::SUBMIT,
$this->onDateCriteriaEvent($formFactory));
$builder->get('selectedGroup')->addEventListener(FormEvents::SUBMIT,
$this->onGroupCriteriaEvent($formFactory));
}
private function onDateCriteriaEvent(FormFactory $ff) {
return
function(FormEvent $event) use ($ff) {
$root = $event->getForm()->getParent();
$requestedDate = $event->getData();
$qb = $this->getQueryBuilder();
$qb->andWhere('r.requestedDate = :requestedDate')
->setParameter('requestedDate', $requestedDate);
if(!$this->searchHasResult($root)) {
$this->addTravels($ff, $root);
}
};
}
private function onGroupCriteriaEvent(FormFactory $ff) {
return
function(FormEvent $event) use ($ff) {
$root = $event->getForm()->getRoot();
$selectedGroup = $event->getData();
$qb = $this->getQueryBuilder();
$qb->andWhere('r.group = :group')
->setParameter('group', $selectedGroup);
if(!$this->searchHasResult($root)) {
$this->addTravels($ff, $root);
}
};
}
private function addTravels(FormFactory $ff, Form $rootForm) {
$travels = $ff->createNamedBuilder('travels', 'entity', null,
array(
'class' => 'MyBundle\Entity\Travel',
'mapped' => false,
'multiple' => true,
'expanded' => true,
'auto_initialize' => false
));
$submitButton = $ff->createNamedBuilder('validate', 'submit');
$travels->addEventListener(FormEvents::PRE_SUBMIT, $this->onSearchResult());
$form->add($travels->getForm())->add($submitButton->getForm());
}
// The method setData() shows "This form should not contain extra fields"
private function onSearchResult() {
return
function(FormEvent $e) {
$data = $this->searchResultQueryBuilder->getQuery()->getResult();
$e->setData($data);
};
}
private function getQueryBuilder() {
if(null === $this->searchQueryBuilder) {
$this->searchResultQueryBuilder = $this->travelRepository->createQueryBuilder('r');
// add dummy where clause here in order to call "andWhere" indistinctly later
$this->searchResultQueryBuilder->where("1 = 1");
}
return $this->searchQueryBuilder;
}
private function searchHasResult(Form $form) {
return $form->has('travels');
}
}
Finally I found a piece of solution.
On $formField->addEventListener() we can set a priority order as the third argument. So I can know which event will be triggered the last.
There must be another solution (like registering all the events I want to monitor in some member array and check if they have been executed in each callback). For the moment setting hardcoded events priority without checking callbacks execution is OK (for only 2 events).
The field is populated during creation and not after but anyway, it works :).
public function buildForm(FormBuilderInterface $builder, array $options) {
$formFactory = $builder->getFormFactory();
$builder
->add('requestedDate', 'date', array(
'widget' => 'single_text',
'input' => 'datetime',
'format' => 'dd/MM/yyyy',
'attr' => array('class' => 'date'),
'data' => null,
'mapped' => false
))
->add('selectedGroup', 'entity', array(
'class' => 'MyBundle\Entity\Group',
'placeholder' => '',
'mapped' => false,
'multiple' => false,
))
->add('search', 'submit');
// Here we could use a register method which would contain listener informations
$builder->get('requestedDate')
->addEventListener(FormEvents::SUBMIT,
$this->onDateCriteriaEvent($formFactory),
0); //Will be triggered first
$builder->get('selectedGroup')
->addEventListener(FormEvents::SUBMIT,
$this->onGroupCriteriaEvent($formFactory),
1); //Will be triggered after 1st
}
private function onDateCriteriaEvent(FormFactory $ff) {
return
function(FormEvent $event) use ($ff) {
$root = $event->getForm()->getParent();
$qb = $this->getQueryBuilder();
if(null !== $event->getData()) {
$requestedDate = $event->getData();
$qb->andWhere('r.requestedDate = :requestedDate')
->setParameter('requestedDate', $requestedDate);
// Here we could check for registered events not already raised
// and do the appropriate action (if it is the last or something else...)
}
};
}
private function onGroupCriteriaEvent(FormFactory $ff) {
return
function(FormEvent $event) use ($ff) {
$qb = $this->getQueryBuilder();
$root = $event->getForm()->getRoot();
if(null !== $event->getData()) {
// Check for events not already raised....
$selectedGroup = $event->getData();
$qb->andWhere('r.group = :group')
->setParameter('group', $selectedGroup);
}
$travels = $qb->getQuery()->getResult();
if($this->searchHasResult($root) {
// We know this event is the last raised so we can add 'travels' field
$this->addTravels($ff, $root);
}
};
}
private function addTravels(FormFactory $ff, Form $rootForm) {
$travels = $ff->createNamedBuilder('travels', 'entity', null,
array(
'class' => 'MyBundle\Entity\Travel',
'mapped' => false,
'multiple' => true,
'expanded' => true,
'auto_initialize' => false
));
$submitButton = $ff->createNamedBuilder('validate', 'submit');
$travels->addEventListener(FormEvents::PRE_SUBMIT, $this->onSearchResult());
$form->add($travels->getForm())->add($submitButton->getForm());
}
I am trying to retrieve data (a dependency) from a database and use the returned values to populate a zend form select element.
The final values should look like below:
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'jobId',
'options' => array(
'label' => 'countryList',
'value_options' => array(
'1'=>'USA',
'2'=> 'United Kingdom',
etc
'
),
),
'attributes' => array(
'value' => '1' //set selected to '1'
)
));
I have used doctrine2 to retrieve the values, i.e:
public function getOptionsForSelect()
{
$entity = $this->getEntityManager()
->getRepository('Workers\Entity\CountryList')
->findAll();
foreach ($entity as $entity)
{
echo $entity->country;
echo $entity->id;
}
}
The above gives me all the required values. I am however stuck on how to then place these values into an array such that once the $this->getOptionsForSelect() is placed in the form, it will immediately populate the values;
i.e.
foreach ($entity as $entity)
{
$id = $entity->id;
$country= $entity->country;
$data['data'] = $id.'=>'.$country;
}
return $data;
The final version of the form field will look like below:
$this->add(array(
'name' => 'countrylist',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'countrylist',
'value_options' => $this->getOptionsForSelect(),
'empty_option' => '--- please choose ---'
)
));
There is ObjectSelect/EntitySelect in DoctrineModule for ZF2 which might simplify this - https://github.com/doctrine/DoctrineModule/blob/master/docs/form-element.md
You don't need your own getOptionsForSelect(), because doctrine can handle that already.
If I understood you correctly, you could implement your getOptionsForSelect like so:
public function getOptionsForSelect()
{
$entity = $this->getEntityManager()
->getRepository('Workers\Entity\CountryList')
->findAll();
$options = array();
foreach ($entity as $entity) {
$options[$entity->id] = $entity->country;
}
return $options;
}
I haven't worked with doctrine, but I'd expect it to have some method to extract data as an array, or at least that I'd be possible to pass it to some serialized object to do that.