ClassNotFoundException: Attempted to load class "Mongo" from... (with persist) symfony2
Asked Answered
R

1

6

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());
    }
}
Rotorua answered 9/1, 2014 at 16:1 Comment(3)
Do you have the MongoDB PHP extension installed? phpinfo() output will tell you.Actually
Show us the config where you defined "doctrine_mongodb" as a service, because i think that the problem is thereCockiness
thanks for the reply. Derick, when I do php -m (using cli) I can see mongo as one of the modules. @gprusiiski, my doctrine_mongodb is below: #MongoDB Configuration doctrine_mongodb: connections: default: server: mongodb://192.168.101.188:27017 options: {} default_database: mp_development document_managers: default: auto_mapping: trueRotorua
R
3

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.

Rotorua answered 9/1, 2014 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.