我想添加一个个人资料图片到我的管理类,但我得到了这个错误:
试图从命名空间"Application mediabundance Entity"加载类"Media"。你是不是忘记用use了?"Sonata medi丰ModelMedia"、"Sonata medi丰TestsEntityMedia"、"Sonata medi丰TestsDocumentMedia"或"Sonata medi丰TestsPHPCRMedia"?
我搜索了很多,但没有解决方案。这是我的代码
用户实体> /**
> * @var ApplicationSonataMediaBundleEntityMedia
> * @ORMManyToOne(targetEntity="ApplicationSonataMediaBundleEntityMedia",
> cascade={"persist"}, fetch="LAZY")
> */
> protected $media;
>
> /**
> * Set media
> *
> * @param ApplicationSonataMediaBundleEntityMedia $media
> * @return User
> */
> public function setMedia(ApplicationSonataMediaBundleEntityMedia $media = null)
> {
> $this->media = $media;
>
> return $this;
> }
>
> /**
> * Get media
> *
> * @return ApplicationSonataMediaBundleEntityMedia
> */
> public function getMedia()
> {
> return $this->media;
> }
用户管理 /**
* @param SonataAdminBundleFormFormMapper $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' => 'ApplicationSonataMediaBundleEntityMedia', 'required' => false))
->end();
}
config.yml
# app/config/config.yml
sonata_media:
class:
media: ApplicationMediaBundleEntityMedia
gallery: ApplicationMediaBundleEntityGallery
gallery_has_media: ApplicationMediaBundleEntityGalleryHasMedia
# if you don't use default namespace configuration
#class:
# media: MyVendorMediaBundleEntityMedia
# gallery: MyVendorMediaBundleEntityGallery
# gallery_has_media: MyVendorMediaBundleEntityGalleryHasMedia
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: DoctrineDBALTypesStringType
doctrine_phpcr:
odm:
auto_mapping: true
mappings:
SonataMediaBundle:
prefix: SonataMediaBundlePHPCR
这是教程有什么帮助吗?
问题在配置文件config.yml
> sonata_media:
> class:
> media: ApplicationSonataMediaBundleEntityMedia
> gallery: ApplicationSonataMediaBundleEntityGallery
> gallery_has_media: ApplicationSonataMediaBundleEntityGalleryHasMedia
> category: ApplicationSonataClassificationBundleEntityCategory