0

I have enabled sfDoctrineGuardPlugin, so I have change myUser class to my class extends sfGuardSecurityUser.

I have overrided sfGuardUser schema to add my own relation

Personnage:
      local: id
      foreign: user_id
      type: one
      onUpdate: CASCADE
      onDelete: CASCADE

When models are generated, if go on BasesfGuardUser.class.php, I can see in PHPDoc comments my relation is created and property Personnage has been added.

 * @property Personnage $Personnage

But I don't understand when I try to access this property, I can't.

In controller :

$user = $this->getUser();
$user->Personnage;

In view :

echo $sf_user->Personnage

And the error :

Notice: Undefined property: myUser::$Personnage

How can I access to this property ?

Elorfin
  • 2,487
  • 1
  • 27
  • 50

1 Answers1

5

You're mixing up two things: the myUser, aka. the session, and the doctrine user, aka. the user's database record.

In symfony projects, the myUser class represents the current session (a wrapper on top of the $_SESSION superglobal).

You can access the database record in you controller via $this->getUser()->getGuardUser(), so your relation will work as $this->getUser()->getGuardUser()->Personnage.

Also see the part regarding user sessions of the Gentle Introduction to symfony book.

Maerlyn
  • 33,687
  • 18
  • 94
  • 85