Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Refine Tags

Snippets tagged "sfguard user" Snippets tagged "sfguard user"

Create profile after adding a new user, the simple way.

Sometimes if you use sfGuardUser and sfGuardUserProfile you need to create an empty profile just after adding the new user (automating is such a great thing). This snippet will help out.

UPDATE: Will Killian pointed me to the solution of using this without touching the plugin files, this way it will still work after upgrading the plugin. Thanks!

Edit apps/backend/modules/sfGuardUser/actions/actions.class.php

(create directories and files as needed, just for the record I use this with admin generator on "backend" app)

Mine looks like this.

<?php
 
require_once(sfConfig::get('sf_plugins_dir').'/sfGuardPlugin/modules/sfGuardUser/lib/BasesfGuardUserActions.class.php');
 
class sfGuardUserActions extends BasesfGuardUserActions
{
  protected function savesfGuardUser($sf_guard_user)
  {
    parent::savesfGuardUser($sf_guard_user);
    $user_id = $sf_guard_user->getId();
    $c = new Criteria();
    $c->add(sfGuardUserProfilePeer::USER_ID,$user_id);
    $profile = sfGuardUserProfilePeer::doSelectOne($c);
    if(!$profile) {
      $profile = new sfGuardUserProfile();
      $profile->setUserId($user_id);
      $profile->save();
    }
  }
}
 
by Roberto Carvajal on 2007-10-30, tagged profile  sfguard  user 
(5 comments)