我们正在Symfony 2中从头开始构建业务应用程序,我在用户注册流程中遇到了一些问题:在用户创建帐户后,他们应该使用这些凭据自动登录,而不是立即被迫再次提供他们的证书.
任何人都有这方面的经验,或能够指出我正确的方向?
我设置了一个监听器类,我将在任何doctrine prePersist上设置ownerid列.我的services.yml文件看起来像这样......
services:
my.listener:
class: App\SharedBundle\Listener\EntityListener
arguments: ["@security.context"]
tags:
- { name: doctrine.event_listener, event: prePersist }
Run Code Online (Sandbox Code Playgroud)
我的班级看起来像这样......
use Doctrine\ORM\Event\LifecycleEventArgs;
use Symfony\Component\Security\Core\SecurityContextInterface;
class EntityListener
{
protected $securityContext;
public function __construct(SecurityContextInterface $securityContext)
{
$this->securityContext = $securityContext;
}
/**
*
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$entityManager = $args->getEntityManager();
$entity->setCreatedby();
}
}
Run Code Online (Sandbox Code Playgroud)
结果是以下错误.
ServiceCircularReferenceException:检测到服务"doctrine.orm.default_entity_manager"的循环引用,路径:"doctrine.orm.default_entity_manager - > doctrine.dbal.default_connection - > my.listener - > security.context - > security.authentication.manager - > fos_user .user_manager".
我的假设是安全上下文已经被注入链中的某个地方,但我不知道如何访问它.有任何想法吗?
我试图在Symfony 2.4中的事件监听器中获取用户ID,但据我所知,EventListener未被控制器调用,因此我无法使用
$这 - >的getUser();
获得身份证的最佳方式是什么?
我想过在调用事件的services.yml中给它.
感谢anyhelp或任何有用的文档.
问候,