找不到与“ SomeBundle\Folder\SomeClass”类的实体相关联的对象管理器。 [英] Unable to find the object manager associated with an entity of class "SomeBundle\Folder\SomeClass"

查看:59
本文介绍了找不到与“ SomeBundle\Folder\SomeClass”类的实体相关联的对象管理器。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Symfony 2.7创建一个用户注册表格。我为此使用了 Symfony自己的指南,并且呈现了表单



当我填写表格并按注册时,出现以下错误。

 无法找到与 UserBundle\Models\User类的实体关联的对象管理器

这是在以下条件下在 vendor / symfony / symfony / src / Symfony / Bridge / Doctrine / Validator / Constraints / UniqueEntityValidator.php中触发的。 / code>

  $ em = $ this-> registry-> getManagerForClass(get_class($ entity)) ; 
if(!$ em){
抛出新的ConstraintDefinitionException(sprintf(’无法找到与%s类实体相关的对象管理器。’,get_class($ entity))));
}

在我的UserController中的createAction中,实体管理器由<$ c获取$ c> $ em = $ this-> getDoctrine()-> getManager(); 根据Symfony Cookbook中的说明。



我不知道这是怎么回事。感谢您的帮助!



另外,请让我知道是否缺少一些我应该提供的信息。

解决方案

我认为,除非您专门在配置中映射目录,否则该学说将在YourBundle / Entity中查找-这是您的User.php示例与食谱食谱不同的地方。 p>

如果要更改此设置,则需要根据文档



或者,仅将您的User模型转换为\Entity而不是\Models而且我认为会没事的。


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 "UserBundle\Models\User"

This is triggered on the following condition in vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php at line 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)));
        }

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.

解决方案

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

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

这篇关于找不到与“ SomeBundle\Folder\SomeClass”类的实体相关联的对象管理器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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