Answer the question
In order to leave comments, you need to log in
How to make Sonata Admin Bundle work with FieldType Entity in simple_array format?
There are two entities "Category" and "Product". We need to make it possible to edit product categories in multiple mode and store the value as a simple_array.
class Product
. . .
/**
* @var array
*
* @ORM\Column(name="categories", type="simple_array", nullable=true)
*/
private $categories;
public function __construct()
{
$this->categories = new ArrayCollection();
}
class Category
. . .
public function __toString()
{
return (string) $this->id;
}
$formMapper->add('categories', 'entity', array(
'class' => 'Site\AppBundle\Entity\Category',
'choice_label' => 'name',
'multiple' => true
));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question