Create custom template list field for title and name with SonataUserBundle User Entity GENDER constants in SonataAdminBundle

The SonataUserBundle UserInterface uses the following GENDER constants:

We will use the gender to determine the title of a User and prefix it to the full name. To set a custom template in my UserAdmin class we configure the field:

The following custom template uses older Twig Syntax to retrieve the constants:

The following version is recommended and uses Twig Syntax (e.g. “ternary operator”) since 1.12.0:


FOSUserBundle login error ‘Could not convert database value “” to Doctrine Type array’

Refactoring an existing project and migrating to Symfony2 I had to import 4000 users into the FOSUserBundle table fos_user.

I wrote a little import script that unfortunately updated some columns with an empty string. These columns were used by Doctrine for storing arrays:

  • roles (DC2Type:array)
  • facebook_data (DC2Type:json)
  • twitter_data (DC2Type:json)
  • gplus_data (DC2Type:json)

After trying to login I got the following error:

Could not convert database value “” to Doctrine Type array

The solution was to replace the empty string with the expected array e.g.:

If you want to add Roles you can use the FOSUserBundle command line tools:

FOSUserBundle Command Line Tools: