Rectangle 27 0

php How to list objects with a simple array type field on a Symfony project with the Sonata Admin Bundle?


/**
     * @param ListMapper $listMapper
     */
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->add('id')                
            ->add('sizes', 'array') // I've just added array type
            ->add('_action', 'actions', array(
                'actions' => array(
                    'show' => array(),
                    'edit' => array(),
                    'delete' => array(),
                )
            ))
        ;
    }
    /**
     * @param ShowMapper $showMapper
     */
    protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            ->add('id')                
            ->add('sizes', 'array') // I've just added array type
        ;
    }

Although the result is not beautiful. I've solved the problem just adding 'array' type to 'sizes' field on configureShowFields and configureListFields methods. The result shows sizes field like [0 => 38] [1 => 40] [2 => 42] [3 => 43] [4 => 45] [5 => 46] and I would like it as similar to 38, 40, 42, 43, 45, 46

I would appreciate a better way. Thanks

Note
Rectangle 27 0

php How to list objects with a simple array type field on a Symfony project with the Sonata Admin Bundle?


But the form to insert data works fine. I can mark some options (sizes) and save the new product. The exception occurs when I want show the stored products on database. Thanks for a quick answer :)

You have to specifie that sizes is a collection , add 'sizes', 'collection'. This is working line SF2 form. Types can be found here, you'll found collections' attributes too: http://symfony.com/fr/doc/current/reference/forms/types.html

Note