如何从 sfUser 中获取 id? [英] How to catch an id from sfUser?

查看:11
本文介绍了如何从 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.

这篇关于如何从 sfUser 中获取 id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆