Answer the question
In order to leave comments, you need to log in
Symfony 2 Forms + Doctrine MongoDb
I am writing a project on Symfony 2.1 in the Doctrine MongoDb bundle. There was a problem with forms.
There is a class Consultant:
/**
* @MongoDB\Document
*/
class Consultant
{
/**
* @MongoDB\Id(strategy="NONE")
*/
protected $id;
/**
* @MongoDB\EmbedMany(targetDocument="Specialization", strategy="set")
*/
protected $specs;
/**
* @MongoDB\Hash
*/
protected $schedule;
// далее идут getters/setters
}
/**
* @MongoDB\Document
*/
class Specialization
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\String
*/
protected $name;
public function __toString()
{
return $this->name;
}
// далее идут getters/setters
}
{
"_id": "1",
"specs": [
{
"_id": ObjectId("50d1c5116146a13948000000"),
"name": "Юрист"
},
{
"_id": ObjectId("50d069336146a10244000000"),
"name": "Экономист"
}
],
"themes": ["Финансы", "Здоровье", "Семья", "Бизнес", "Недвижимость"]
}
@
Hash
doctrine annotation). class ConsultantFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('themes', 'collection', array(
'type' => 'choice',
'options' => array(
'expanded' => true,
'multiple' => true,
),
));
}
}
Expected argument of type "array", "string" given
in the ChoicesToBooleanArrayTransformer.php file.$builder->add('themes', 'choice', array(
'choices' => array('Финансы', 'Здоровье', 'Семья', 'Бизнес'), // чисто для эксперимента
'expanded' => true,
'multiple' => true,
));
@EmbedMany
) field. public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\ConsultantBundle\Document\Consultant',
));
}
$builder->add('specs', 'document', array(
'class' => 'AcmeConsultantBundle:Specialization',
'property' => 'name',
'expanded' => true,
'multiple' => true,
));
Answer the question
In order to leave comments, you need to log in
@EmbedMany do you really need it here?
It seems to me that @ReferenceMany is more suitable, your last definition should work with it correctly
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question