Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "profile"

Using timers to profile functions speed

This snippet allows you to evaluate functions speed and display them in symfony debug bar.

$timer = sfTimerManager::getTimer ('ldap_request'); // Create and start a new timer
 
// do some stuff
 
$timer->addTime (); // stop and store the timer value
 
by Arnaud Didry on 2009-06-22, tagged performance  profile  speed 
(2 comments)

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)