I've a class that represent a product with a property mapped as simple array that represents a sizes collection
<?php
namespace Middleware\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Product
*
* @ORM\Table(name="product", uniqueConstraints={...})
* @ORM\Entity(repositoryClass="...")
*/
class Product {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
// more properties
// ...
/**
* @ORM\Column(type="simple_array", nullable=true)
*/
private $sizes;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set sizes
*
* @param array $sizes
* @return Product
*/
public function setSizes($sizes)
{
$this->sizes = $sizes;
return $this;
}
/**
* Get sizes
*
* @return array
*/
public function getSizes()
{
return $this->sizes;
}
}
My ProducAdmin class is like follows
<?php
namespace Middleware\MainBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
class ProductAdmin extends Admin
{
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('id')
->add('sizes') // I get a error ContextErrorException: Notice: Array to string conversion
;
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('id')
->add('sizes') // I get a error ContextErrorException: Notice: Array to string conversion
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$sizes = array();
for ($index = 35; $index <= 48; $index++) {
$sizes[$index] = $index . "";
}
$formMapper
->add('sizes', 'choice', array('required' => false, 'expanded' => true, 'multiple' => true, 'choices' => $sizes)) // works fine
;
}
/**
* @param ShowMapper $showMapper
*/
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('id')
->add('sizes') // I get a error ContextErrorException: Notice: Array to string conversion
;
}
}
How could I manage a field like sizes with Sonata Admin Bundle? Thanks very much