尝试从命名空间“Application\MediaBundle\Entity”加载类“Media”
Posted
技术标签:
【中文标题】尝试从命名空间“Application\\MediaBundle\\Entity”加载类“Media”【英文标题】:Attempted to load class "Media" from namespace "Application\MediaBundle\Entity"尝试从命名空间“Application\MediaBundle\Entity”加载类“Media” 【发布时间】:2017-03-23 01:14:16 【问题描述】:我想在我的管理类中添加个人资料图片,但出现此错误:
尝试从命名空间“Application\MediaBundle\Entity”加载类“Media”。 您是否忘记了“使用”声明,例如“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】:问题出在配置文件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
【讨论】:
以上是关于尝试从命名空间“Application\MediaBundle\Entity”加载类“Media”的主要内容,如果未能解决你的问题,请参考以下文章
尝试从命名空间“Application\MediaBundle\Entity”加载类“Media”
尝试从命名空间“App\DataFixtures”加载类“BaseFixture”。您是不是忘记了另一个名称空间的“使用”语句?