Answer the question
In order to leave comments, you need to log in
How to output select entity in collection field type?
There is an entity Brief and a Category (many-to-many relationship), on the Brief creation page there should be a list with categories. SELECT should not be multiple , so of course everything would work. Entity Brief has addCategory methods etc. The problem is that with this entry:
->add('categories', 'collection', array(
'type'=>'entity',
'options' => array(
'class' => 'Aplication\UserBundle\Entity\Category',
'property' => 'name',
'query_builder' => function(EntityRepository $repository){
return $repository->findAll();
}),
'by_reference' => false
))
Answer the question
In order to leave comments, you need to log in
class Brief{
.....
public functioon getCategory()
{
return $this->categories;
}
public functioon setCategory( $category )
{
$this->categories->clear(); // если надо
$this->addCategory( $category );
}
}
class BriefType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
......
$builder->add( 'category', 'entity', array(
.......
) );
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question