0

so... I basically follow the practical symfony book, and encountered following problem. I have properly (i guess) installed sfGuardPlugin, built the models, sqls etc, created user and tried to log in with the username and password entered.

i got the following error message:

Fatal error: Call to undefined method sfGuardUserPeer::retrieveByUsername() in /***/plugins/sfGuardPlugin/lib/validator/sfGuardValidatorUser.class.php on line 53

it looks quite weird to me, because the problematic part of sfGuardValidatorUser class looks like this:

// user exists?
if ($user = sfGuardUserPeer::retrieveByUsername($username))
{
  // password is ok?
  if ($user->getIsActive() && $user->checkPassword($password))
  {
    return array_merge($values, array('user' => $user));
  }
}

while sfGuardUserPeer has just the empty class:

class sfGuardUserPeer extends PluginsfGuardUserPeer
{
}

that extends PluginsfGuardUserPeer, so i checked it out too:

class PluginsfGuardUserPeer extends BasesfGuardUserPeer
{
  public static function retrieveByUsername($username, $isActive = true)
  {
    $c = new Criteria();
    $c->add(self::USERNAME, $username);
    $c->add(self::IS_ACTIVE, $isActive);

    return self::doSelectOne($c);
  }

}

that's the missing function!

so - what is wrong? why doesn't it work? i have already tried all the solutions found with google, but none of them work :/

Community
  • 1
  • 1
khartvin
  • 551
  • 1
  • 7
  • 20
  • I guess you already clear your cache? rebuilt all lib, etc .. ? – j0k Jul 11 '12 at 10:22
  • obviously i did so... cleared cache with symfony cc, as well as manually deleting the folder – khartvin Jul 11 '12 at 10:29
  • 1
    Maybe there's two sfGuardUserPeer classes. Try searching "class sfGuardUserPeer" in all the code. Be sure you're wathing the one right (you can also unserialize cache/project_autoload.cache file searching for the class file path). – glerendegui Jul 11 '12 at 18:54
  • hmm, that makes sense. i don't see any other such a class at first glance, but i'll check for it. thanks for the suggestion :) – khartvin Jul 12 '12 at 06:52

2 Answers2

1

finally found it!

the

symfony propel:build-model

task unnecessarily generated the sfGuard classes in the model directory from the schema file located in the plugin directory, while all the classes were already present in the sfGuard folder.

geez, that shouldn't happen in such a well-developed framework and plugin...

khartvin
  • 551
  • 1
  • 7
  • 20
1

Simply put that

public static function retrieveByUsername($username, $isActive = true)
  {
    $c = new Criteria();
    $c->add(self::USERNAME, $username);
    $c->add(self::IS_ACTIVE, $isActive);

    return self::doSelectOne($c);
  } 

Code into your sfGuardUserPeer class, this will sort out the issue, I did the same when I got this error, it worked for me..

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
Mohammed
  • 35
  • 2
  • 9