首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将mongodb连接到codeigniter 3上原理为2的数据库

将mongodb连接到codeigniter 3上原理为2的数据库
EN

Stack Overflow用户
提问于 2016-05-26 23:14:03
回答 1查看 604关注 0票数 0

我们目前正在安排工作以完成我们的队形。我们项目的目标是改进我们公司现有的web应用程序,使用Codeigniter框架进行开发。该应用程序使用带有PhpMyAdmin的mysql数据库。我们必须在mongoDB和DoctrineODM中使用另一个数据库。我们从getcomposer安装Composer开始。我们使用Composer将Doctrine集成到使用此链接的解释的CodeIgniter中:http://blog.beheist.com/integrating-codeigniter-and-doctrine-2-orm-with-composer/之后,我们集成库mongoDB与此处解释的设置:mongoDB在尝试创建到数据库的连接后,我们的工作安置导师删除先前创建的bootstrap.php文件。我们还从这里将doctrine.php文件替换为DoctrineODM.php : github.com/openstepmedia/cibongo/blob/dev/bonfire/libraries/DoctrineODM.php我们对代码做了一些修改,因为我们没有使用Bonfire。

DoctrineODM.php

代码语言:javascript
复制
//phpinfo(); exit();


use Doctrine\Common\ClassLoader,
    Doctrine\ODM\MongoDB\Configuration,
    Doctrine\Common\Annotations\AnnotationReader,
    Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver,
    Doctrine\ODM\MongoDB\DocumentManager,
    Doctrine\MongoDB\Connection;
/**
 * Doctrine bootstrap library for CodeIgniter
 *
 * @author  Joseph Wynn <joseph@wildlyinaccurate.com>
 * @link    http://wildlyinaccurate.com/integrating-doctrine-2-with-codeigniter-2
 */
class DoctrineODM
   {
   public $em;    
   public $dm;
   public function __construct()
{
        require APPPATH.'config/doctrine.php';

        // With this configuration, your model files need to be in application/models/Entity
        // e.g. Creating a new Entity\User loads the class from application/models/Entity/User.php
        //$models_namespace = 'Documents';
    // Set up driver
        foreach (glob(APPPATH . 'modules/*', GLOB_ONLYDIR) as $m) {
            $module = str_replace(APPPATH . 'modules/', '', $m);
            $loader = new ClassLoader($module, APPPATH . 'modules');
            $loader->register();
        }



        $models = array(APPPATH . 'models');
        $loader = new ClassLoader('models/', $models);
        $loader->register();

        foreach (glob(APPPATH . 'modules/*/models', GLOB_ONLYDIR) as $m) {
            array_push($models, $m);
        }
        //$models_path = APPPATH . 'models';
        $proxies_dir = APPPATH . 'models/Proxies';
        $hydrators_dir = APPPATH . 'models/Hydrators';
        $metadata_paths = array(APPPATH . 'models');
        $config = new Configuration();
        $config->setDefaultDB($db['default']['database']);
        $config->setProxyDir($proxies_dir);
        $config->setProxyNamespace('Proxies');
        $config->setHydratorDir($hydrators_dir);
        $config->setHydratorNamespace('Hydrators');
        //$annotationDriver = $config->newDefaultAnnotationDriver(array($models_path . '/Documents'));
        $annotationDriver = $config->newDefaultAnnotationDriver($models);
        $config->setMetadataDriverImpl($annotationDriver);
        AnnotationDriver::registerAnnotationClasses();
        try {
        $connection = new Connection($db['default']['server'] );
            $this->dm = DocumentManager::create($connection, $config);
        } catch (Exception $ex) {
            var_dump($e->getMessage());
        }
        //$this->generate_classes();
}

也许这不是一个好的选择,但在那之后,连接(MongoClient)仍然是NULL。然后我们自己创建了类models/Entity/User.php来检查Doctrine是否正常工作。我们得到这个错误:

代码语言:javascript
复制
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/www/fast-mage/admin/applicationhiddenci/librariesKint/Kint.php:276)
Filename: core/Common.php
Line Number: 573

An uncaught Exception was encountered
Type: Doctrine\Common\Persistence\Mapping\MappingException
Message: Class 'User' does not exist
Filename: /home/www/fast-mage/admin/applicationhiddenci/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php
Line Number: 96

我们现在阻塞了数据(服务器、主机名、id、…),我们不知道从哪里查找的数据库在DocumentManager上,但MongoClient保持为NULL。感谢您的阅读,为我糟糕的英语感到抱歉,并感谢您的帮助。

EN

回答 1

Stack Overflow用户

发布于 2016-05-30 15:40:57

错误是很明显的:

代码语言:javascript
复制
Class 'User' does not exist

你创建了你的User实体吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37464830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档