ClassNotFoundException:尝试从......加载类“Mongo”(带有持久性)symfony2

时间:2014-01-09 16:01:28

标签: php mongodb symfony persistence doctrine-mongodb

我在使用http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html上的doctrine mongodb cookbook将mongodb与Symfony(版本2.5.0-DEV)集成时遇到了一些问题。

对于'持久对象到MongoDB'阶段,一切都还可以。当我添加“$dm->persist($script);”行时,我的远程数据库没有任何反应,我收到错误消息:

ClassNotFoundException:尝试从/var/www/Symfony/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Connection.php第283行中的全局命名空间加载类“Mongo”。您是否忘了使用这个班的陈述?

但如果没有持久行,脚本会解析而不会出错(但远程数据库没有任何反应)。

这是我的Symfony版本(2.5.0)特有的,是否有解决方法?我在下面粘贴了我的整个脚本,包括use语句。任何帮助,将不胜感激 :)。

namespace Atlas\MpBundle\Controller;
use Atlas\MpBundle\Document\Scripts;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class UserjsonController extends Controller
{
    public function showuserjsonAction()
    {
        $script = new Scripts();
        $script->setName('kingstest');
        $script->setDescription('just a desc test');
        $script->setGroup('SMS');

        $dm = $this->get('doctrine_mongodb')->getManager();
        $dm->persist($script);
        $dm->flush();

        return new Response('Created New Document in scripts with script id '.$script->getId());
    }
}

1 个答案:

答案 0 :(得分:3)

谢谢你们。现在工作。 扩展名mongo.so必须在php.ini中加载,我编辑了错误的php.ini文件。将extension=mongo.so添加到位于 / etc / php5 / apache2 / 中的php.ini,现在可以正常运行:) 希望这可以帮助将来的某个人。