Symfony: sfDoctrineGuardPlugin and Customizing User Profile

sfDoctrineGuardPlugin provides basic authentication. sf_guard_user table only contains minimal fields to make this feature work. All other user relevant information such as name, birthday, contact numbers etc require a new table sf_guard_user_profile that works with this.

However at the moment user profile setup is poorly documented from the official plugin page.

Further information can be found here on how to customize the user profile for frontend and backend. Note that this was written for Symfony V1.2, some commands maybe be obsoleted and needed to be replaced with newer commands.

Here are some main points from the document.

User profile schema

Add in config/doctrine/schema.yml to create a 1-1 relation between sfGuardUser and sfGuardUserProfile:

  tableName: sf_guard_user_profile
  actAs:        { Timestampable: ~, Signable: ~ }
  options:      { collate: utf8_unicode_ci, charset: utf8 }
    id:         { type: integer(4), primary: true, autoincrement: true }
    user_id:    { type: integer(4), notnull: true }
    fullname:   { type: string(80) }
    email:      { type: string(100) }
      class: sfGuardUser
      foreign: id
      local: user_id
      type: one
      onDelete: cascade
      foreignType: one
      foreignAlias: Profile

Sample data for data/fixture:

    username:       admin
    password:       admin
    is_super_admin: true
      fullname:     Administrator
    username:       user
    password:       user
    is_super_admin: false
      fullname:     User

Embed profile in user form

Step 1:

cp plugins/sfDoctrineGuardPlugin/lib/form/doctrine/sfGuardUserAdminForm.class.php lib/form/doctrine/

Step 2: edit the form

public function configure()
  $profileForm = new ProfileForm($this->object->Profile);
  unset($profileForm['id'], $profileForm['sf_guard_user_id']);
  $this->embedForm('Profile', $profileForm);

Step 3: manually create module for sfGuardUser and edit generator.yml:

  class: sfDoctrineGenerator
        class: sfGuardUserAdminForm
          "NONE": [username, password, password_again, Profile]
          "Permissions and groups": [is_active, is_super_admin, groups_list, permissions_list]

2 thoughts on “Symfony: sfDoctrineGuardPlugin and Customizing User Profile

  1. Ryan Reply

    Thank you for the instructions. As you know, documentation on sfDoctrineGuardPlugin is lacking.

    Unfortunately, I encounter two errors. The first is minor in that Signable does not appear to be supported anymore. The second one causes more trouble. The User Profile schema and fixtures examples given above throw errors for me in symfony 1.4 with mysql 5:
    SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ” for key 2

    I fixed this by eliminating the user_id column from sfGuardUserProfile and changing the relationship to use id for the local key and the foreign key. This makes more logical sense as well, and was something that I was planning to try anyway after getting everything working. Preliminary tests suggests that this fixes the problem.

    Crossing my fingers that it won’t cause problems down the road.

  2. Ahmed Reply

    Thanks bro!

    Just a little issue with Symfony 1.4.16.

    When editing config/doctrine/schema.yml, have user_id integer(8), so that it will be compatible with sfDoctrineGuard.

    user_id: { type: integer(8), notnull: true }


Leave a Reply

Your email address will not be published. Required fields are marked *