symfony : myUser class => How to access custom property
I have enabled sfDoctrineGuardPlugin, so I have change myUser
class to my开发者_JAVA百科 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 ?
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.
精彩评论