Silex和Doctrine - ORMException:未知实体命名空间别名[半固定] [英] Silex and Doctrine - ORMException: Unknown Entity namespace alias [semi fixed]

查看:151
本文介绍了Silex和Doctrine - ORMException:未知实体命名空间别名[半固定]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的使用silex构建的应用程序中使用Doctrine组件。我有能力让它工作 - 几乎可以。



我有我的用户实体和相应的存储库



当执行

  $ app ['em']  - > getRepository('Foo\Entity\User' ) - > findAll()

按预期工作,但是当尝试进行自定义查询时p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

FROM
Foo:用户u
WHERE c.id =:x'

- > setParameter('x',$ in)
- >的getResult();

我得到这个例外

  ORMException:未知实体命名空间别名'Foo'

请忽略我可以使用 findById() findBy(array('id'=> $ in))问题在于自定义查询



这是我的配置

  $ app ['orm.em.options'] = array(
'mappings'=> array(
array(
'type'=>'annotation',
'namespace'=>'Foo\Entity',
'alias'=>'core',
'path'=>'%app.path%/ src / Foo / Entity' ,
'use_simple_annotation_reader'=> false,

));

  $ config = Setup :: createAnnotationMetadataConfiguration(array(__ DIR __。/ src / Foo / Entity)); 
$ params = $ app ['db.options'];
$ app ['em'] = EntityManager :: create($ params,$ config);

经过一些研究可能的解决方案:




  • auto_mapping:true =>尝试,没有成功

  • 注册命名空间=>尝试,不知道如果正确完成,可能是解决方案,请建议如何这样做正确

  • 除了这一切,我试图搜索类似使用的git repos,但没有得到它:(



更新



目前我在查询中使用以下行, p>

  FROM 
InstaLikes\Entity\User u


解决方案

当您创建自定义查询时,您应该使用完整的命名空间,在这种情况下:
Foo\Entity\\ \\用户


I'm trying to use the Doctrine components in my app built using silex. I was able to get it to work - well almost.

I have my "User" entity and the corresponding repository

When doing

$app['em']->getRepository('Foo\Entity\User')->findAll()

works as expected, however when trying to make a custom query

      $this->getEntityManager()
                ->createQuery(
                'SELECT
                    u
                FROM 
                    Foo:User u
                WHERE c.id = :x'
                )
                ->setParameter('x',$in)
                ->getResult();

I get this exception

ORMException: Unknown Entity namespace alias 'Foo'

Please ignore the fact that I can make a select with findById() or findBy(array('id'=>$in)) the problem is with the custom query

This are my configs

$app['orm.em.options'] = array(
    'mappings' => array(
        array(
            'type' => 'annotation',
            'namespace' => 'Foo\Entity',     
            'alias' => 'core',
            'path' => '%app.path%/src/Foo/Entity',
            'use_simple_annotation_reader' => false,
        )
));

and

$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src/Foo/Entity"));
$params = $app['db.options'];
$app['em'] = EntityManager::create($params, $config);

After some research possible solutions:

  • auto_mapping: true => tried, no success
  • registering the namespace => tried, not sure if right was done so may be the solution, please advice how to do it right
  • besides all this I have tried to search for git repos with similar 'usage' but didn't get it :(

UPDATE

for the moment I use the following line in my query and it works

FROM 
InstaLikes\Entity\User u

解决方案

When you create custom queries, you should use the fully namespace, in this case: Foo\Entity\User

这篇关于Silex和Doctrine - ORMException:未知实体命名空间别名[半固定]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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