【问题标题】:Class was not found in the chain configured namespaces (zend framework 2 and doctrine 2)在链配置的命名空间中找不到类(zend 框架 2 和学说 2)
【发布时间】:2015-05-22 20:02:51
【问题描述】:

当我尝试在控制器中使用实体时出现以下错误:

在 C:\xampp\htdocs\zf2_pr6\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php 中的链配置命名空间中找不到类“Application\Entity\User”: 37

我的module.config.php 配置包括

'doctrine' => array(
    'driver' => array(
        'application_entities' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/Application/Entity')
        ),
    ),
    'connection' => array(
        'orm_default' => array(
            'driverClass' => 'Doctrine\DBAL\Driver\PDOMysql\Driver',
            'params' => array(
                'host' => 'localhost',
                'port' => '3306',
                'user' => 'root',
                'password' => '',
                'dbname' => 'zf2',
            ),
        ),
    ),
),
'orm_default' => array(
    'drivers' => array(
        'Application\Entity' => 'application_entities',
    ),
),

我还创建了其他相关文件的粘贴箱

如何解决这个错误,将我的驱动程序添加到配置的命名空间链中?

【问题讨论】:

  • 我忘记在我的控制器上从 pastebin 使用 Doctrine\ORM\EntityManager 复制,它包含在我的代码中
  • 你在使用DoctrineORMModule吗?如果是,您必须将Application\Entity 命名空间注册到映射驱动程序。 github.com/doctrine/DoctrineORMModule#entities-settings
  • 嗨,布拉姆,我正在使用 DoctrineORMModule,它是根据您的文档配置的。你可以在这里看到我的 module.config.php:pastebin.com/fHD4sWdd 根据 orm:validate-schema 映射也是可以的
  • @BeniaminGheorghita 我已经更新了您的问题,以便更好地解释您的问题。如果您觉得编辑不正确,请随时恢复或编辑我的更改。将来,请直接在您的问题中添加任何相关代码,以便其他可能遇到相同问题的人不必处理死链接等。

标签: doctrine-orm zend-framework2


【解决方案1】:

您的配置不正确。目前你在'doctrine'键下有'orm_default'配置 - 这意味着驱动程序永远不会添加到Doctrine。

您需要将驱动程序配置和“orm_default”配置放在同一级别,在doctrine/driver 下。

'doctrine' => array(
    'driver' => array(

        'application_entities' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/Application/Entity')
        ),

        'orm_default' => array(
            'drivers' => array(
                'Application\Entity' => 'application_entities',
            ),
        ),
    )
),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-24
    • 2011-04-06
    • 1970-01-01
    相关资源
    最近更新 更多