symfony: sfDoctrineGuardPlugin and customizing user profile

by prettyscripts on 2010-03-03 11:43:54 • Leave a comment »

symfony

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:

Code:

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

sample data for data/fixture:

Code:

sfGuardUser:
  sgu_admin:
    username:       admin
    password:       admin
    is_super_admin: true
    Profile:
      fullname:     Administrator
      email:        admin@some.email.address
  sgu_user:
    username:       user
    password:       user
    is_super_admin: false
    Profile:
      fullname:     User
      email:        user@some.email.address

embed profile in user form

step 1:

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

step 2: edit the form

PHP:

public function configure()
{
  parent::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:

Code:

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

Tags: doctrine, profile, symfony, user

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
note: all comments are moderated. do not spam and do not advertise. only comments relevant to the post will be published.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)