2016-11-09 69 views
1

我想向我的管理員類添加個人資料圖片,但出現此錯誤: 沒有與上下文相關的主要類別:默認 我搜索了很多,但沒有解決方案。這是我的代碼 config.yml沒有與上下文相關的主要類別:默認

# app/config/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 

    default_context: default # you need to set a context 
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here 
    contexts: 
     default: 
      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: 
      service: sonata.media.provider.image 
      resizer: sonata.media.resizer.square # sonata.media.resizer.square 
      filesystem: sonata.media.filesystem.local 
      cdn:  sonata.media.cdn.server 
      generator: sonata.media.generator.default 
      thumbnail: sonata.media.thumbnail.format 
      allowed_extensions: ['jpg', 'png', 'jpeg'] 
      allowed_mime_types: ['image/pjpeg', 'image/jpeg', 'image/png', 'image/x-png'] 
     file: 
      service: sonata.media.provider.file 
      resizer: false 
      filesystem: sonata.media.filesystem.local 
      cdn:  sonata.media.cdn.server 
      generator: sonata.media.generator.default 
      thumbnail: sonata.media.thumbnail.format 
      allowed_extensions: ['pdf', 'txt', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'odg', 'odp', 'ods', 'odc', 'odf', 'odb', 'csv', 'xml', 'sql'] 
      allowed_mime_types: ['text/csv','application/pdf', 'application/x-pdf', 'application/rtf', 'application/octet-stream', 'text/html', 'text/rtf','application/sql', 'text/plain','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-excel','application/x-iwork-numbers-sffnumbers','application/vnd.apple.numbers'] 

doctrine: 
    orm: 
     entity_managers: 
      default: 
       mappings: 
        FOSUserBundle: ~ 
        SonataMediaBundle: ~ 
    dbal: 
     types: #this is about this line and line below 
      json:  \Doctrine\DBAL\Types\StringType 

userAdmin

/** 
    * @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' => 'default', 
        //'data_class' => 'Application\Sonata\MediaBundle\Entity\Media', 
        'required' => false) 
      ) 
      ->end(); 
    } 

用戶實體

class User extends BaseUser 
{ 
    /** 
    * @var int 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 


    /** 
    * @var 
    * 
    * @ORM\Column(name="firstname", type="string") 
    */ 
    protected $firstname; 


    /** 
    * @var 
    * 
    * @ORM\Column(name="lastname", type="string") 
    */ 
    protected $lastname; 

    /** 
    * @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; 
    } 

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

    /** 
    * @return String 
    */ 
    public function getFirstname() 
    { 
     return $this->firstname; 
    } 

    /** 
    * @param String $firstname 
    */ 
    public function setFirstname($firstname) 
    { 
     $this->firstname = $firstname; 
    } 

    /** 
    * @return String 
    */ 
    public function getLastname() 
    { 
     return $this->lastname; 
    } 

    /** 
    * @param String $lastname 
    */ 
    public function setLastname($lastname) 
    { 
     $this->lastname = $lastname; 
    } 
} 

任何幫助嗎?對不起英文。

回答

3

在Github的頁面有an issue where a contributor suggests運行此命令:

php app/console sonata:classification:fix-context

你得到這個錯誤的原因是因爲你想添加的背景下default媒體,但上下文無關(鏈接)到一個類別。