When setting up ZF2 + ODM, I'm getting the following error:
The class 'Application\Document\User' was not found in the chain configured namespaces
The current setup is as the following:
ZF2 stable, installed doctrine ODM via composer.phar with content of composer.json
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"minimum-stability": "dev",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.0.0",
"doctrine/doctrine-mongo-odm-module": "dev-master"
}
}
modules loaded
'modules' => array(
'Application',
'DoctrineModule',
'DoctrineMongoODMModule',
),
hydrator and proxy dirs are created
$ ls -l data/DoctrineMongoODMModule/
total 0
drwxrwxrwx 2 wisu staff 68 Sep 12 08:34 Hydrators
drwxrwxrwx 2 wisu staff 68 Sep 12 08:35 Proxy
the odm config looks like
'driver' => array(
'odm_default' => array(
'drivers' => array(
'Application\Document' => 'aplikasi'
)
),
'aplikasi' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
'module/Application/src/Application/Document'
)
)
),
I'm trying to use the following mapping
<?php
namespace Application\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/** @ODM\Document(collection="user") */
class User
{
/** @ODM\Id */
private $id;
/** @ODM\Field(type="string") */
private $name;
/**
* @return the $id
*/
public function getId() {
return $this->id;
}
/**
* @return the $name
*/
public function getName() {
return $this->name;
}
/**
* @param field_type $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* @param field_type $name
*/
public function setName($name) {
$this->name = $name;
}
}
but calling it via
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Document\User;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$user = new User();
$user->setName("Gembul");
$dm->persist($user);
$dm->flush();
return new ViewModel();
}
}
Any pointers?
Real solution is not adding module.doctrine-mongo-odm.local.php into autoload directory, this lines worked for me as configuration
'driver' => array(
'ODM_Driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../../module/Application/src/Application/Doctrine/Document')
),
'odm_default' => array(
'drivers' => array(
'Application\Doctrine\Document' => 'ODM_Driver'
)
),
),