MongoDB类文档不存在symfony 2

时间:2014-12-04 16:58:27

标签: mongodb symfony

我刚刚用fosuserbundle和DoctrinemongodbBundle安装了symfony2。

FOS配置了mongodb并且运行良好

我尝试在mongodb文档中设置并获取一些数据

这是我的文件:

<?php
// src/Acme/UserBundle/Document/Video.php

namespace Tube\VideoBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document
 */
class Video
{
    /**
     * @MongoDB\Id(strategy="auto")
     */
    protected $id;

    /**
     * @MongoDB\Int
     */
    protected $uid;

    /**
     * @MongoDB\String
     */
    protected $type;

    /**
     * @MongoDB\String
     */
    protected $embed;

    /**
     * @MongoDB\String
     */
    protected $url;



    /**
     * Get id
     *
     * @return id $id
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set uid
     *
     * @param int $uid
     * @return self
     */
    public function setUid($uid)
    {
        $this->uid = $uid;
        return $this;
    }

    ......
}

这是我的控制器:

<?php

namespace Tube\VideoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Tube\VideoBundle\Document\Video;


class DefaultController extends Controller
{
    public function addVideo($uid, $type, $embed, $url)
    {
        $video = new Video;

        $video->setUid($uid);
        $video->setType($type);
        $video->setEmbed($embed);
        $video->setUrl($url);

        $em = $this->getDoctrine()->getManager();
        $em->persist($video);
        $em->flush();

        return new Response($video->getId());
    }

    public function indexAction()
    {
        $video = $this->addVideo(1, "YouTube", '<iframe width="560" height="315" src="//www.youtube.com/embed/pA8Kzh_GWvw?list=UUEJFNw_gfbaoJnHfFguvI_w" frameborder="0" allowfullscreen></iframe>', "http://youtu.be/pA8Kzh_GWvw?list=UUEJFNw_gfbaoJnHfFguvI_w");

        return $this->render('TubeVideoBundle:Default:index.html.twig', array('id' => $video));
    }
}

Symfony错误:

The class 'Tube\VideoBundle\Document\Video' was not found in the chain configured namespaces 

我哪里错了?

config.yml

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

doctrine_mongodb:
    connections:
        default:
            server: mongodb://localhost:27017
            options: {}
    default_database: test_database
    document_managers:
        default:
            auto_mapping: true

堆栈追踪:

[1] Doctrine\Common\Persistence\Mapping\MappingException: The class 'Tube\VideoBundle\Document\Video' was not found in the chain configured namespaces 
    at n/a
        in /usr/local/var/www/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 37

    at Doctrine\Common\Persistence\Mapping\MappingException::classNotFoundInNamespaces('Tube\VideoBundle\Document\Video', array())
        in /usr/local/var/www/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php line 113

    at Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass('Tube\VideoBundle\Document\Video', object(ClassMetadata))
        in /usr/local/var/www/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php line 117

    at Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(object(ClassMetadata), null, false, array())
        in /usr/local/var/www/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php line 318

    at Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('Tube\VideoBundle\Document\Video')
        in /usr/local/var/www/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php line 211

    at Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('Tube\VideoBundle\Document\Video')
        in /usr/local/var/www/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 295

    at Doctrine\ORM\EntityManager->getClassMetadata('Tube\VideoBundle\Document\Video')
        in /usr/local/var/www/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1610

    at Doctrine\ORM\UnitOfWork->doPersist(object(Video), array('000000003c91b7fb0000000117989f94' => object(Video)))
        in /usr/local/var/www/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1583

    at Doctrine\ORM\UnitOfWork->persist(object(Video))
        in /usr/local/var/www/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 624

    at Doctrine\ORM\EntityManager->persist(object(Video))
        in /usr/local/var/www/Symfony/src/Tube/VideoBundle/Controller/DefaultController.php line 26

    at Tube\VideoBundle\Controller\DefaultController->addVideo('1', 'YouTube', '&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;//www.youtube.com/embed/pA8Kzh_GWvw?list=UUEJFNw_gfbaoJnHfFguvI_w&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;', 'http://youtu.be/pA8Kzh_GWvw?list=UUEJFNw_gfbaoJnHfFguvI_w')
        in /usr/local/var/www/Symfony/src/Tube/VideoBundle/Controller/DefaultController.php line 34

    at Tube\VideoBundle\Controller\DefaultController->indexAction()
        in  line 

    at call_user_func_array(array(object(DefaultController), 'indexAction'), array())
        in /usr/local/var/www/Symfony/app/bootstrap.php.cache line 2987

    at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
        in /usr/local/var/www/Symfony/app/bootstrap.php.cache line 2949

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
        in /usr/local/var/www/Symfony/app/bootstrap.php.cache line 3098

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
        in /usr/local/var/www/Symfony/app/bootstrap.php.cache line 2348

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
        in /usr/local/var/www/Symfony/web/app_dev.php line 28

0 个答案:

没有答案