试图加载课程" Media"来自命名空间" Application \ MediaBundle \ Entity"

时间:2016-11-09 09:17:52

标签: php symfony sonata-admin sonata sonata-media-bundle

我想在我的管理类中添加个人资料图片,但是我收到了这个错误:

尝试加载课程" Media"来自命名空间" Application \ MediaBundle \ Entity"。 你忘记了"使用"例如声明" Sonata \ MediaBundle \ Model \ Media"," Sonata \ MediaBundle \ Tests \ Entity \ Media"," Sonata \ MediaBundle \ Tests \ Document \ Media"或" Sonata \ MediaBundle \ Tests \ PHPCR \ Media"?

我搜索了很多但没有解决方案。 这是我的代码

用户实体

>  /**
>      * @var \Application\Sonata\MediaBundle\Entity\Media
>      * @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media",
> cascade={"persist"}, fetch="LAZY")
>      */
>     protected $media;
> 
>     /**
>      * Set media
>      *
>      * @param \Application\Sonata\MediaBundle\Entity\Media $media
>      * @return User
>      */
>     public function setMedia(\Application\Sonata\MediaBundle\Entity\Media $media = null)
>     {
>         $this->media = $media;
> 
>         return $this;
>     }
> 
>     /**
>      * Get media
>      *
>      * @return \Application\Sonata\MediaBundle\Entity\Media
>      */
>     public function getMedia()
>     {
>         return $this->media;
>     }

用户管理

 /**
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
     *
     * @return void
     */
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General')
            ->add('username')
            ->add('email')
            ->add('enabled')
            ->add('firstname')
            ->add('lastname')
            ->add('plainPassword', 'password', array(
                'required' => (!$this->getSubject() || is_null($this->getSubject()->getId())),
            ))
            ->add('media', 'sonata_media_type', array('provider' => 'sonata.media.provider.image', 'context' => 'engine', 'data_class' => 'Application\Sonata\MediaBundle\Entity\Media', 'required' => false))
            ->end();
    }

config.yml

# app/config/config.yml

sonata_media:
    class:
        media: Application\MediaBundle\Entity\Media
        gallery: Application\MediaBundle\Entity\Gallery
        gallery_has_media: Application\MediaBundle\Entity\GalleryHasMedia
    # if you don't use default namespace configuration
    #class:
    #    media: MyVendor\MediaBundle\Entity\Media
    #    gallery: MyVendor\MediaBundle\Entity\Gallery
    #    gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
    default_context: default # you need to set a context
    contexts:
        default:  # the default context is mandatory
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file
                - sonata.media.provider.vimeo

            formats:
                small: { width: 100 , quality: 70}
                big:   { width: 500 , quality: 70}
        # other contexts here
        engine:
            providers:
                - sonata.media.provider.image

            formats:
                preview:   { width: 100, quality: 100}
                small:     { width: 200, quality: 100}
                large:     { width: 600, quality: 100}
    cdn:
        server:
            path: /uploads/media # http://media.sonata-project.org/

    filesystem:
        local:
            directory:  "%kernel.root_dir%/../web/uploads/media"
            create:     false
    providers:
        image:
            resizer: sonata.media.resizer.square

doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    FOSUserBundle: ~
                    SonataMediaBundle: ~
    dbal:
        types: #this is about this line and line below
            json:     \Doctrine\DBAL\Types\StringType
doctrine_phpcr:
    odm:
        auto_mapping: true
        mappings:
            SonataMediaBundle:
                prefix: Sonata\MediaBundle\PHPCR

这是tutoruial 任何帮助? 抱歉英语

1 个答案:

答案 0 :(得分:0)

问题出在配置文件 config.yml

> sonata_media:
>     class:
>         media: Application\Sonata\MediaBundle\Entity\Media
>         gallery: Application\Sonata\MediaBundle\Entity\Gallery
>         gallery_has_media: Application\Sonata\MediaBundle\Entity\GalleryHasMedia
>         category:   Application\Sonata\ClassificationBundle\Entity\Category