没有找到类“MongoId”(Zend Framework with MongoDB Doctrine) [英] Class 'MongoId' not found (Zend Framework with MongoDB Doctrine)

查看:105
本文介绍了没有找到类“MongoId”(Zend Framework with MongoDB Doctrine)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在尝试在ZendFramework中整合MongoDB与Doctrine。我做了很多教程(在StackOverflow或其他任何地方),但没有什么是真正的工作。



我按照一步一步的教程: http://www.bigwisu.com/2012/10/03/zend-framework-2 -doctrine-odm ,我收到一个我不明白的错误。

 致命错误:Class'MongoId 'not found in /home/prooxi/www/zframework/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Types/IdType.php on line 38 

IdType.php是mongoDB的源代码,因此错误必须位于其他位置。
这是我有的文件。 (管理员是模块的名称)



config / application.config.php

 code><?php 
return array(
'modules'=> array(
'Application',
'DoctrineModule',
'DoctrineMongoODMModule ',
'Udmin',
'Listing',
'Admin',
),

'module_listener_options'=>数组(
'module_paths'=>数组(
'./module',
'./vendor',
),

'config_glob_paths'=>数组(
'config / autoload / {,*。} {global,local} .php',
),

),

) ;

config / autoload / module.doctrine-mongo-odm.local.php

 <?php 
返回数组(
'doctrine'=>数组(

'连接'=>数组(
'odm_default'=>数组(
'server'=>'MYDBADRESS',
'port'=>'27017',
/ *'connectionString'=> null,* /
/ *'user'=> null,* /
/ *'password'=> null,* /
' dbname'=>'px_boutique_test27',
'options'=> array()
),
),

'configuration'=>数组(
'odm_default'=>数组(
'metadata_cache'=>'array',
'driver'=>'odm_default',
'generate_proxies'= > true,
'proxy_dir'=>'data / DoctrineMongoODMModule / Proxy',
/ *'proxy_dir'=> __DIR__。'/ module / Admin / src / Admin / Model / ,* /
/ *'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'=>数组(
'odm_default'=>数组(
'drivers'=>数组(
'Admin\Document'=>'aplikasi'

),
'aplikasi'=>数组(
'class'=>'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'cache '=>'array',
'paths'=> array(
'module / Admin / src / Admin / Document'


) ,
'documentmanager'=>数组(
'odm_default'=>数组(
'connection'=>'odm_default',
'configuration'=>'odm_default',
'eventmanager'= >'odm_default'

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

),

),
);

模块/管理员/ Src /管理员/控制器/ AdminController.php

 <?php 
命名空间Admin\Controller;

使用Zend\Mvc\Controller\AbstractActionController;
使用Zend\View\Model\ViewModel;
使用Mongo;
使用Zend\Session\SaveHandler\MongoDB;
使用Zend\Session\SaveHandler\MongoDBOptions;
使用Zend\Session\SessionManager;
使用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 
返回数组(
'controllers'=>数组(
'invokables'=>数组(
'Admin\Controller\Admin'=>'Admin\Controller\AdminController',
),
),

'router'=>数组(
'routes'=>数组(
'admin'=>数组(
'type'=>'segment' ,
'options'=>数组(
'route'=>'/ admin [/] [:action] [/:id]',
'constraints'=>数组(
'action'=>' [a-zA-Z] [a-zA-Z0-9 _-] *',
'id'=> '[0-9] +',
),
'defaults'=>数组(
'controller'=>'Admin\Controller\Admin',
'action'=>'index',
),
),
),
),
),

'view_manager'=>数组(
'template_path_stack'=>数组(
'admin'=> __DIR__。'/../view',
),
),

);

该模块的目的是连接到现有的MongoDB数据库,只需制作所有文件中。



谢谢!



Gilles

解决方案

如果您使用的是较新的mongodb扩展名,而不是PHP的mongo扩展名,则需要使用MongoDB \BSON\ObjectID,详见 php.net 页面


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

解决方案

If you are using the newer mongodb extension rather than mongo extension for PHP you will need to use MongoDB\BSON\ObjectID as detailed on the php.net page

这篇关于没有找到类“MongoId”(Zend Framework with MongoDB Doctrine)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆