Question

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

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

<?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

<?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.

Was it helpful?

Solution

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.

namespace Application\Document;

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

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

    // ...

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top