简体   繁体   English

在Zend Framework 2模块结构内映射许多名称空间时出现错误

[英]Doctrine error in mapping many namespaces inside Zend Framework 2 module structure

I'm getting an error from Doctrine2 while it tries to map my class structure. 在尝试映射我的类结构时,Doctrine2出现错误。

My Zend Application's modules is structured as follows: 我的Zend应用程序的模块结构如下:

module
    ModuleOne
        config
            module_config.php
        src
            ModuleOne
                Entity
                    ClassOne.php
            ModuleOneAdmin
                Entity
                    ClassTwo.php
                    ClassTwoRepository.php
        Module.php
    ModuleTwo
        config
            module_config.php
        src
            ModuleTwo
                Entity
                    ClassThree.php
        Module.php

I've two subnamespaces inside ModuleOne, so, my autoloader (in ModuleOne/Module.php) is configured this way: 我在ModuleOne中有两个子命名空间,因此,我的自动加载器(在ModuleOne / Module.php中)是按以下方式配置的:

public function getAutoloaderConfig()
{
    return array(
        'Zend\Loader\StandardAutoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ . 'Admin' => __DIR__ . '/src/' . __NAMESPACE__ . 'Admin',
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
            ),
        ),
    );
}

In ModuleOne/config/module_config.php, the doctrine is configured 在ModuleOne / config / module_config.php中,配置了该理论

'doctrine' => array(
    'driver' => array(
        __NAMESPACE__ . '_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(
                __DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'
            )
        ),
        'orm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
            ),
        ),
    ),
)

I'm using the ModuleOne and ModuleTwo in another module (that I didn't specified in modules structure to avoid making it exhaustive) that possesses Controllers and Views. 我在另一个具有Controllers和Views的模块中使用ModuleOne和ModuleTwo(在模块结构中未指定该模块,以避免使其变得面面俱到)。

When I run my application, it gets and error in a line that calls for a repository of the an Entity: 当我运行我的应用程序时,它在一行中出现错误,并要求一个Entity的存储库:

$repository = $this->getEm()->getRepository('ModuleOneAdmin\Entity\ClassTwo');

The error is: 错误是:

The class 'ModuleOneAdmin\Entity\ClassTwo' was not found in the chain configured namespaces ModuleOne\Entity, ModuleTwo\Entity

I've searched a lot of other questions about something like this here in StackOverflow and in others sites from a google search, but none addressed my issue. 我已经在StackOverflow和Google搜索的其他站点中搜索了很多类似这样的问题,但是都没有解决我的问题。 Its like the Doctrine can't find my ModuleOneAdmin in its internal mappings. 就像教义在其内部映射中找不到我的ModuleOneAdmin一样。 Is there some configuration that I'm missing? 我缺少一些配置吗?

Thanks in advance. 提前致谢。

I've found the problem, I didn't included the path to the drivers of the admin entities folder, in the doctrine configurations. 我发现了问题,但没有在理论配置中包含管理实体文件夹的驱动程序路径。

With the code below it works. 使用下面的代码,它可以工作。

'doctrine' => array(
    'driver' => array(
        __NAMESPACE__ . '_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(
                __DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'
            )
        ),
        'orm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver',
                __NAMESPACE__ . 'Admin\Entity' => __NAMESPACE__ . '_driver'
            ),
        ),
    ),
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM