Im' currently trying to integrate MongoDB with Doctrine in ZendFramework. I did a lot of tutorial (on StackOverflow or anywhere else) but nothing is really working.
I followed step by step a tutorial: http://www.bigwisu.com/2012/10/03/zend-framework-2-doctrine-odm and I got an error that I don't understand.
Fatal error: Class 'MongoId' not found in /home/prooxi/www/zframework/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Types/IdType.php on line 38
The IdType.php is source code for the mongoDB, so the error must be somewhere else. Here is the files I have. (Admin is the name of the module)
config/application.config.php
<?php
return array(
'modules' => array(
'Application',
'DoctrineModule',
'DoctrineMongoODMModule',
'Udmin',
'Listing',
'Admin',
),
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
),
);
config/autoload/module.doctrine-mongo-odm.local.php
<?php
return array(
'doctrine' => array(
'connection' => array(
'odm_default' => array(
'server' => 'MYDBADRESS',
'port' => '27017',
/* 'connectionString' => null, */
/* 'user' => null, */
/* 'password' => null, */
'dbname' => 'px_boutique_test27',
'options' => array()
),
),
'configuration' => array(
'odm_default' => array(
'metadata_cache' => 'array',
'driver' => 'odm_default',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineMongoODMModule/Proxy',
/* 'proxy_dir' => __DIR__ . '/module/Admin/src/Admin/Model/Proxy', */
/* 'proxy_dir' => __DIR__ . '/module/Udmin/src/Udmin/Model/Proxy', */
'proxy_namespace' => 'DoctrineMongoODMModule\Proxy',
/* 'proxy_namespace' => 'Udmin\Model\Proxy', */
'generate_hydrators' => true,
'hydrator_dir' => 'data/DoctrineMongoODMModule/Hydrator',
/* 'hydrator_dir' => __DIR__ . '/module/Udmin/src/Udmin/Model/Hydrator', */
'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator',
/* 'hydrator_namespace' => 'Udmin\Model\Hydrator', */
'default_db' => 'test27',
'filters' => array(), // array('filterName' => 'BSON\Filter\Class'),
/* 'logger' => null // 'DoctrineMongoODMModule\Logging\DebugStack' */
)
),
'driver' => array(
'odm_default' => array(
'drivers' => array(
'Admin\Document' => 'aplikasi'
)
),
'aplikasi' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
'module/Admin/src/Admin/Document'
)
)
),
'documentmanager' => array(
'odm_default' => array(
'connection' => 'odm_default',
'configuration' => 'odm_default',
'eventmanager' => 'odm_default'
)
),
'eventmanager' => array(
'odm_default' => array(
'subscribers' => array()
)
),
),
);
Module/Admin/Src/Admin/Controller/AdminController.php
<?php
namespace Admin\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Mongo;
use Zend\Session\SaveHandler\MongoDB;
use Zend\Session\SaveHandler\MongoDBOptions;
use Zend\Session\SessionManager;
use Admin\Document\Boutique;
class AdminController extends AbstractActionController
{
public function indexAction()
{
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$b = new Boutique();
/* $dm->getRepository('Admin\Document\Boutique')->findAll(); */
$dm->find('Admin\Document\Boutique', '52e6c677362dca7fcd40ab09');
}
}
Module/Admin/config/module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Admin\Controller\Admin' => 'Admin\Controller\AdminController',
),
),
'router' => array(
'routes' => array(
'admin' => array(
'type' => 'segment',
'options' => array(
'route' => '/admin[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Admin\Controller\Admin',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'admin' => __DIR__ . '/../view',
),
),
);
The purpose of the module is to connect to an existing MongoDB databate and just make a list of all the document in it.
Thank you !
Gilles
use
statement or prefixed the class with a backslash; I.Enew \MongoId($id)
? – Brow