如何从 sfUser 中获取 id?
我正在使用 symfony 1.4 &我使用 sfDoctrineGuardPlugin 作为身份验证工具.
I'm working with symfony 1.4 & i use sfDoctrineGuardPlugin as a tool for authentifications.
我想获取用户的 ID 以便将其存储在我的表中.
I want to catch the Id of user in order te store it in my table.
经过一个小的研究,我想我必须使用那个表达式:getUser()->getGuardUser()->getId()
.
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.
推荐答案
如果用户通过了身份验证,是的,你可以使用:
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.
相关文章