简体   繁体   English

ZF2-Doctrine2 MongoDB ODM-“在链配置名称空间中找不到该类”

[英]ZF2 - Doctrine2 MongoDB ODM - “The class was not found in the chain configuration namespaces”

I've seen the same error posted often here and have read through and made changes based on the previous questions and answers, to no avail. 我看到了经常在此处发布的同一错误,并且已根据先前的问题和答案进行了通读并进行了更改,但无济于事。

I have installed Doctrine's Mongo ODM with Zend Framework via Composer and completed the installation as described here 我已经通过Composer安装了带有Zend Framework的Doctrine的Mongo ODM,并按照此处所述完成了安装。

https://github.com/doctrine/DoctrineMongoODMModule https://github.com/doctrine/DoctrineMongoODMModule

I have modified my /config/autoload/module.doctrine-mongo-odm.local.php file beyond the recommendations of the above documentation in an effort to fix my problem and based on answers to similar questions here, so that it now looks as follows 我已经修改了/config/autoload/module.doctrine-mongo-odm.local.php文件,超出了上述文档的建议,以解决我的问题并基于此处类似问题的答案,因此现在看起来像跟随

<?php
return array(
    'doctrine' => array(

        'connection' => array(
            'odm_default' => array(
                'server'    => 'removed.mongolab.com',
                'port'      => '43957',
                'user'      => 'removed',
                'password'  => 'removed',
                'dbname'    => 'richard',
                'options'   => array()
            ),
        ),

        'configuration' => array(
            'odm_default' => array(
                'metadata_cache'     => 'array',
                'driver'             => 'odm_default',
                'generate_proxies'   => true,
                'proxy_dir'          => 'data/DoctrineMongoODMModule/Proxy',
                'proxy_namespace'    => 'DoctrineMongoODMModule\Proxy',
                'generate_hydrators' => true,
                'hydrator_dir'       => 'data/DoctrineMongoODMModule/Hydrator',
                'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator',
                'default_db'         => 'richard',
                'filters'            => array(),
                'logger'             => null
            )
        ),

        'odm_default' => array(
            'drivers' => array(
                'Application\Document' => 'odm_driver'
            )
        ),

        'odm_driver' => array(
            'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(
                'module/Application/src/Application/Document'
            ),
        ),

        'documentmanager' => array(
            'odm_default' => array(
                'connection'    => 'odm_default',
                'configuration' => 'odm_default',
                'eventmanager' => 'odm_default'
            )
        ),

        'eventmanager' => array(
            'odm_default' => array(
                'subscribers' => array()
            )
        ),
    ),
);

I have a file /module/Application/src/Application/Document/User.php as follows 我有一个文件/module/Application/src/Application/Document/User.php如下

<?php

namespace Application\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations;

class User {

    /** @ODM\Id */
    private $id;

    /** @ODM\Field(type="bin_data_timestamp") */
    private $timestamp;

    /** @ODM\Field(type="string") */
    private $username;

    /** @ODM\Field(type="bin_data_md5") */
    private $password;

    /** @ODM\Field(type="bin_data_uuid") */
    private $salt;

    /** @ODM\Field(type="string") */
    private $realName;

    /** @ODM\Field(type="string") */
    private $email;

    public function getId() {

        return $this->id;

    }

    // ...

    public function setId($id) {

        $this->id = $id;

    }

    // ...

}

In my controller, I'm using the following code. 在我的控制器中,我正在使用以下代码。

$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$user = new User;

$user->setUsername("test");

$dm->persist($user);
$dm->flush();

However, I'm getting the infamous error 但是,我收到了臭名昭著的错误

The class 'Application\Document\User' was not found in the chain configured namespaces 

Any assistance would be greatly appreciated. 任何帮助将不胜感激。

My configuration had become a bit confused, as it turns out. 事实证明,我的配置有些混乱。 I was able to correct the issue with the following configuration code. 我可以使用以下配置代码来解决此问题。

    'driver' => array(
        'odm_driver' => array(
            'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
            'paths' => array(__DIR__ . '/../../module/Application/src/Application/Document')
        ),
        'odm_default' => array(
            'drivers' => array(
                'Application\Document' => 'odm_driver'
            )
        ),
    ),

NB: The included code for Application\\Document\\User also produces errors, corrected with the following code. 注意:Application \\ Document \\ User包含的代码也会产生错误,并通过以下代码进行了纠正。

namespace Application\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/** @ODM\Document */
class User {

    // ...

}

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

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