The Friendly Web Guys

The Jimmyweb Blog

Symfony Tip: Admin Generator + sfGuardPlugin + SfGuard Profile

5th
August

2009

Posted by James Beattie - under News 1 Comment

tip

If you get the error “Call to undefined method BasesfGuardUser::addsfGuardUserProfile” when using a custom sfGuardUser profile, you need to add the following method to the file /plugins/sfGuardPlugin/lib/model/sfGuardUser.php

  public function addsfGuardUserProfile()
  {
    if(!$profile = $this->getProfile())
    {
      $profile = new sfGuardUserProfile;
      $profile->setUserId($this->getId());
    }
    return $profile;
  }

I know it sucks to hack a core plugin file, but sometimes we must pragmatic!

Tags: ,

Symfony Tip: Propel pager with group-by returns incorrect total

27th
June

2009

Posted by James Beattie - under Developer 2 Comments

tip

A quick tip for those getting incorrect record totals (and thus broken paging) when using the propel pager in Symfony:

Add the following method to your pager object:

$pager->setPeerCountMethod('getGroupedCount');

Then create the following method in your peer class:

    public static function getGroupedCount($c)
    {
        $copy = clone $c;
        // this should be the intended grouping column
        $copy->addGroupByColumn(parent::ID);
        return parent::doCount($copy);
    }

Your pager will now work the way you want it to!

Tags: ,