How to catch an id from sfUser?(如何从 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 sfUser 中获取 id?


基础教程推荐
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01
- php中的PDF导出 2022-01-01