Chad 2010-06-08

There's a sfGuardUser in the sfDoctrineGuardPlugin, which is using the `sf_guard_user` table. After installation of the plugin, by default that table only contains the least columns for security purpose, not even there's a column to store an email address.

To extend it, I think there are at least two ways:

1. ovrride the `sf_guard_user` table schema;

2. add a new table to store more custom user information.

 

Both of the solutions are very useful. For example, we can do the following configuration:

Code - YMLPlain Text
 
  1. // config/doctrine/schema.yml  
  2.   
  3. #...  
  4.   
  5. sfGuardUser:  
  6.   columns:  
  7.     user_type:  { type: integer(1) }  
  8.   
  9. #...  

With this, we will have an additional `user_type` column added into the `sf_guard_user` table.

 

We can also add a completely new table and add a foreign key constraint to the extended custom table:

Code - YMLPlain Text
 
  1. // config/doctrine/schema.yml  
  2.   
  3. #...  
  4.   
  5. CustomUser:  
  6.   columns:      
  7.     guard_user_id:    { type: integer(4), notnull: true }      
  8.     email:            { type: string(45), notnull: true }  
  9.   relations:      
  10.     GuardUser:   
  11.       class: sfGuardUser  
  12.       local: guard_user_id  
  13.       foreign: id  
  14.       foreignAlias: CustomUser  
  15.       foreignKeyName: fk_custom_user_sf_guard_user  
  16.       foreignType: one  
  17.       onDelete: CASCADE  
  18.   
  19. #...  

It's important to know that we should use "integer(4)" for that `guard_user_id` column. Because it's a foreign key, it should match the data type of the `id` column in `sf_guard_user` table, which is also "integer(4)". Otherwise SQL error (errno: 150) would occur when running the generated SQL script.

 



More