- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题:在我的登录 Controller 中,我得到了用户对象。但是当我转到仪表板时,用户对象是空的。
登录 Controller
if ($this->isAuthUser($request)) {
$signinUser = $request->get('signin');
$token = new UsernamePasswordToken($signinUser, null, 'secured_area', $signinUser->getRoles());
$this->get("security.context")->setToken($token);
$event = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
$session = $this->get('session');
$session->set('user', $signinUser->getUsername());
}
安全.yml
security:
providers:
in_memory:
memory: ~
access_control:
#- { path: ^/(signin|signup)?$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
firewalls:
secured_area:
pattern: ^/
anonymous: true
form_login:
login_path: /signin
check_path: _security_check
access_denied_url: signin
# logout:
# path: /signout
# #target: /
# invalidate_session: false
# delete_cookies:
# a: { path: null, domain: null }
# b: { path: null, domain: null }
# #handlers: [some.service.id, another.service.id]
# #success_handler: some.service.id
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
default:
anonymous: true
token 对象:Signincontroller
Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken Object
(
[credentials:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] =>
[providerKey:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => secured_area
[user:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Headset\Bundle\AccountsBundle\Entity\User Object
(
[email:Headset\Bundle\AccountsBundle\Entity\User:private] => operator1@flavr.com
[password:Headset\Bundle\AccountsBundle\Entity\User:private] => operator123#46
[oldPassword:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[id:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[userId:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[firstName:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[lastName:Headset\Bundle\AccountsBundle\Entity\User:private] =>
[username:Headset\Bundle\AccountsBundle\Entity\User:private] => operator1@flavr.com
)
[roles:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
[0] => Symfony\Component\Security\Core\Role\Role Object
(
[role:Symfony\Component\Security\Core\Role\Role:private] => ROLE_USER
)
)
[authenticated:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => 1
[attributes:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
)
)
仪表板 Controller
Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken Object
(
[credentials:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] =>
[providerKey:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => secured_area
[user:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] =>
[roles:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
[0] => Symfony\Component\Security\Core\Role\Role Object
(
[role:Symfony\Component\Security\Core\Role\Role:private] => ROLE_USER
)
)
[authenticated:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => 1
[attributes:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
)
)
请问有谁知道是什么原因吗?
任何帮助将不胜感激......
最佳答案
可能问题出在配置上。根据配置的用户提供者部分,您根本就没有任何用户。
security:
providers:
in_memory:
memory: ~
查看关于 users loading 的 symfony 文档
关于交响乐 2.5 : $this->getUser() is empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26354920/
我目前正在学习 Symfony 和 Doctrine reading the docs . 我不明白 find 和 findOneById 之间的区别。我尝试在这个简单的示例中使用它们,看起来它们对我
我有基本模板(base.html.twig),其中包含动态生成的 js 链接: 以及呈现此 JS 的 Action: /** * @Route("/scripts.js",
在我的 Symfony 4 项目中,我有一个包含 HTML 的变量,我尝试用 Twig 显示它。我想使用 template_from_string() 函数,但我必须将 Twig_Extension_
我想重载 include_http_metas() 帮助程序(来自 AssetHelper 类)以使其符合 HTML5。 有什么想法吗? 非常感谢。 最佳答案 只需复制您应用的 lib/helper
我继承了一个零文档的 Symfony/PHP 网络应用程序代码库。我是一名 nodejs 开发人员,因此您可以想象其中的乐趣......!无论如何,我要做到这一点,我的重点是能够在本地运行该项目。 这
我有一个用户可以登录的表单。 登录后,我会将用户重定向到仪表板页面。 问题:在我的登录 Controller 中,我得到了用户对象。但是当我转到仪表板时,用户对象是空的。 登录 Controller
我得到的完整错误是这个。 在“FooBlogBundle:Article:articles.html”中呈现模板期间抛出异常(“缺少一些强制性参数(“id”)以生成路由“FooBlogBund
我需要 symfony 1.4 操作,它将接收模板名称列表作为参数,并将这些呈现的模板作为 JSONed 哈希返回。这是代码: foreach ($templateNames as $template
我需要 symfony 1.4 操作,它将接收模板名称列表作为参数,并将这些呈现的模板作为 JSONed 哈希返回。这是代码: foreach ($templateNames as $template
我目前正在处理一个项目,之前的开发人员将其与 JMSTranslationBundle 集成在一起。此刻,我对应用程序做了一些修改,其中之一是将菜单变成高度动态的。 (基本上,应用程序的用户逻辑有 3
我正在从事 Symfony 2 WebApp 项目。集成商店的逻辑在 MyShopBundle 中实现。 在将 Twig Extension 添加到 bundle 后,我得到一个异常: 我完全理解这条
我已将模型与实体分开。我有三个具有相应实体的模型:Review、RatedReview 和 ScoredReview。他们的关系是 ScoredReview 扩展 RatedReview 扩展 Rev
*在我将数据添加到我的数据库之前,我添加第一行后,evry thigns 工作正常,我收到此消息 “警告:preg_match() 期望参数 2 为字符串,给定对象”以及存储在我的数据库中的数据...
是否可以在 Twig(在 Symfony 中)中获取数组的键? 例如,如果我有一个数组: array( 'key1' => 'value1', 'key2' => 'value2', ); 是否可以在
我想输出一个包含数字的数组。 我正在创建这样的数组(它收到了过去 7 天的统计信息): from('stJob j') ->where('j.created_at = ?', date('
我开始实现 HWIOAuthBundle 并想创建我自己的自定义资源所有者。但是我不清楚文件/目录结构。 我需要将文件放在哪里才能利用 bundle ? 最佳答案 我覆盖了 HWIOAuthBundl
早上好,我告诉你我的情况。我在 Symfony 下的项目中使用的数据库删除了一个表和外键。导入映射 (XML) 并生成实体后,所有这些都会自动使用 Symfony 控制台;当我访问项目的任何页面时,显
我是 Symfony 3 的新手(之前我使用 Yi 1,现在我想尝试一些新东西)。 我很困惑,结构看起来如此不同 - 框架似乎与应用程序逻辑混在一起。 我现在要将什么 checkin git?当然,我
我正在使用 symfony 4,如果我在 Command 类中,我想访问一个实体的存储库。没有函数 getDoctrine 或其他东西.. 我通过控制台创建了一个实体,所以我得到了一个实体和一个存储库
组件没有 setTemplate()!我知道,但也许还有另一种方法可以做到这一点? (问题似乎是关于一个php框架:http://www.symfony-project.org/) 最佳答案 sfCo
我是一名优秀的程序员,十分优秀!