Skip to content

choice_value: Call to a member function non-object #21116

@hous04

Description

@hous04
Q A
Bug report? yes
Symfony version 3.2.1

I'm using Symfony3.2 , I get this error when using choice_value in the formType but it works good with symfony3.1

"Error: Call to a member function getSlug() on a non-object" at D:\wamp\www\my_project\src\AppBundle\Form\Bien\BienType.php line 77

use AppBundle\Entity\Ville;
//......
->add('ville', EntityType::class, array(

            'class' => 'AppBundle:Ville',
            'label' => 'Ville',
            'choice_label' => 'nom',
            'placeholder' => 'Ville ',
            'multiple' => false,
            'expanded' => false,
            'choice_value' => function ($ville) {
                /** @var Ville $ville */
                return $ville->getSlug();
            },
        ))

but it works fine with choice_label:

'choice_label' => function ($ville) {
                /** @var Ville $ville */
                return $ville->getSlug();
            },

I have the same code with choice_value in another project with Symfony3.1 and it works good.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions