phpsymfony1doctrinesfguard

How to catch an id from sfUser?


I'm working with symfony 1.4 & i use sfDoctrineGuardPlugin as a tool for authentifications.

I want to catch the Id of user in order te store it in my table.

After a small research, I guess I have to use that expression : getUser()->getGuardUser()->getId().

What i looking for is how to invest that expression for my target.


Solution

  • if the user is authenticated, yes, you can use:

    // inside an action
    $id = $this->getUser()->getGuardUser()->getId();
    
    // inside a template
    $id = $sf_user->getGuardUser()->getId();
    

    If the user is not authenticated, it'll throw an error.