ClassNotFoundException: Attempted to load class “Mongo” from… (with persist) symfony2

橙三吉。 提交于 2019-12-23 09:32:27

问题


I am having some issue integrating mongodb with Symfony (version 2.5.0-DEV) using the doctrine mongodb cookbook on http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html.

Everything is okay up to the 'Persisting Objects to MongoDB' stage. When I add the line "$dm->persist($script);", nothing happens to my remote database and I get the error message:

ClassNotFoundException: Attempted to load class "Mongo" from the global namespace in /var/www/Symfony/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Connection.php line 283. Did you forget a use statement for this class?

But without the persist line, the script parses without errors (but nothing happens at the remote database).

Is this particular to my Symfony version (2.5.0) and is there a workaround? I have pasted my entire script below including the use statements. Any help would be appreciated :).

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:


Thanks guys. Works now. the extension mongo.so has to be loaded in php.ini and I edited the wrong php.ini file. Added extension=mongo.so to php.ini located in /etc/php5/apache2/ and now it works :) Hopefully this can help someone in the future.



来源:https://stackoverflow.com/questions/21025123/classnotfoundexception-attempted-to-load-class-mongo-from-with-persist-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!