沃梦达 / 编程问答 / php问题 / 正文

无法找到与类“SomeBundleFolderSomeClass"的实体关联的对象管理器.

Unable to find the object manager associated with an entity of class quot;SomeBundleFolderSomeClassquot;(无法找到与类“SomeBundleFolderSomeClass的实体关联的对象管理器.)

本文介绍了无法找到与类“SomeBundleFolderSomeClass"的实体关联的对象管理器.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Symfony 2.7,我正在尝试创建一个用户注册表单.我为此使用了 Symfony 自己的指南,并呈现了表单并且可填充.

Using Symfony 2.7, I am trying to create a user registration form. I've used Symfony's own guide for this, and the form is rendered and fillable.

当我填写表格并按注册"时,我收到以下错误.

When I fill in the form, and press "Register", I get the following error.

Unable to find the object manager associated with an entity of class "UserBundleModelsUser"

这是在 vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php 第 75 行的以下条件下触发的

$em = $this->registry->getManagerForClass(get_class($entity));
        if (!$em) {
            throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class "%s".', get_class($entity)));
        }

在我的 UserController 的 createAction 中,实体管理器由 $em = $this->getDoctrine()->getManager(); 按照 Symfony Cookbook 中的说明获取.

In the createAction in my UserController, the Entity Manager is fetched by $em = $this->getDoctrine()->getManager(); as per the instructions in the Symfony Cookbook.

我不知道这里发生了什么.任何帮助表示赞赏!

I can't find out what's going here. Any help appreciated!

另外,如果缺少一些我应该提供的信息,请告诉我.

Also, please let me know if there is some information missing that I should have provided.

推荐答案

我认为除非您在配置中专门映射一个目录,否则学说将在 YourBundle/Entity 中查找 - 这是您的 User.php 示例与食谱食谱.

I think unless you specifically map a directory in your config, doctrine is going to look in YourBundle/Entity - this is where your User.php example diverges from the cookbook recipe.

如果你想改变它,你需要根据 文档

If you want to change this you'll need to specify it explicitly as per the documentation

或者只是将您的用户模型转移到 Entity 而不是 Models,我认为它会没问题.

Alternatively just shift your User model to Entity instead of Models and I think it'll be OK.

这篇关于无法找到与类“SomeBundleFolderSomeClass"的实体关联的对象管理器.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无法找到与类“SomeBundleFolderSomeClass"的实体关联的对象管理器.

基础教程推荐