How to catch an id from sfUser?

后端 未结 2 1499
梦谈多话
梦谈多话 2021-01-22 00:01

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.

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-22 00:19

    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.

提交回复
热议问题