Question

Related to this post I want to transform a manual adding of a form element to Annotations in my Entity.

The code looks like this:

$this->add(array(
    'name'       => 'formElementName',
    'type'       => 'DoctrineModule\Form\Element\ObjectSelect',
    'attributes' => array(
        'required' => true
    ),
    'options'    => array(
        'label'           => 'formElementLabel',
        'empty_option'    => '--- choose formElementName ---',
        'object_manager'  => $this->getEntityManager(),
        'target_class'    => 'Mynamespace\Entity\Entityname',
        'property'        => 'nameOfEntityPropertyAsSelect'
    )
));

As an annotation I have the problem that the object_manager is a variable which I cannot pass to annotations. Every other attribute is no problem and should work when being annotated.

I'm looking for the correct way to do this:

$form->get('formElementName').setOptions(array('object_manager'=>$entityManager)

Any ideas?

Was it helpful?

Solution

you have to try this it will working fine.

<!-- language-all: lang-html -->
foreach($cityArr as $city){

  $city_ar[$city['id']] = $city['city'];

}

$form->user_city->setMultiOptions($city_ar);

$form->user_city->setValue($val["user_city"]);  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top