5

I try to install the Sonata Media Bundle into the Symfony CMF following this guide: https://sonata-project.org/bundles/media/3-x/doc/reference/installation.html. This command

php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle

makes a whole new bundle ApplicationSonataMediaBundle with a few entities:

  • Gallery
  • GalleryHasMedia
  • Media

But i get the error that the entity Category does not exist when i want to go to the next step:

app/console doctrine:schema:update --force

This is the complete error:

[Doctrine\ORM\Mapping\MappingException]                                                                                                  
  The target-entity Application\Sonata\ClassificationBundle\Entity\Category cannot be found in 'Application\Sonata\MediaBundle\Entity\Med  
  ia#category'.

Is there somebody who can help me to solve this?

Thanks in advance.

Update:

# sonata_classification.yml:

sonata_classification:
    # ...

doctrine:
    orm:
        entity_managers:
            default:
                #metadata_cache_driver: apc
                #query_cache_driver: apc
                #result_cache_driver: apc
                mappings:
                    #ApplicationSonataClassificationBundle: ~
                    SonataClassificationBundle: ~
Frank B
  • 3,667
  • 1
  • 16
  • 22

4 Answers4

6

I had to set this configuration options to get it to work:

sonata_media:
    class:
        media: Application\MediaBundle\Entity\Media
        gallery: Application\MediaBundle\Entity\Gallery
        gallery_has_media: Application\MediaBundle\Entity\GalleryHasMedia
    # ...

And also:

doctrine_phpcr:
    # ...

    odm:
        auto_mapping: true
        mappings:
            SonataMediaBundle:
                prefix: Sonata\MediaBundle\PHPCR
            ApplicationSonataMediaBundle:
                prefix: Application\Sonata\MediaBundle\PHPCR
Frank B
  • 3,667
  • 1
  • 16
  • 22
4

I had the same problem after installing news bundle (which brings classification and media bundles with it). I configured both media and classification before news and received the same error as OP. After looking into the code I noticed that media bundle allows for another class to be specified for category. This stopped the error for me.

sonata_media:
    class:
        # my own bundle namespaces for media and classification bundles
        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
John Pancoast
  • 1,241
  • 16
  • 14
1

Looks like you just need to create a sonata_classification.yml file as described in the classification docs

greg0ire
  • 22,714
  • 16
  • 72
  • 101
  • Thanks greg0ire, i copied and pasted the given example into that file. You can read it in my first post. Should it be enough? – Frank B Jul 25 '16 at 14:38
  • I'm not sure. Just try it, we'll see. – greg0ire Jul 25 '16 at 14:43
  • if i include sonata_classification.yml in config.yml then i am able to request the cmf pages. if i dont include it then the same error shows up as on the cli when i want to update the database but then for the entity media instead of the entity Category. – Frank B Jul 25 '16 at 14:51
  • Either you include it, either you make sure it is loaded. – greg0ire Jul 25 '16 at 14:56
  • hey, you said "if I don't include it then the same error shows up", and now, it also show up when you do include it ?!? – greg0ire Jul 25 '16 at 15:09
  • no but it does when i want to update the database with app/console doctrine:schema:update – Frank B Jul 25 '16 at 16:02
  • 1
    Oh ok. Were both entities generated though? If yes, were their mapping generated too? Can you check that? – greg0ire Jul 25 '16 at 17:49
  • As you can see i posted an answer. Now it looks like its working but i think i have still to configure sonata-admin to let the mediabundle appear somewhere... Thank you for your help greg0ire! – Frank B Jul 25 '16 at 18:24
-1

i solved this problem so:

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Application\Sonata\ClassificationBundle\ApplicationSonataClassificationBundle(),
        // ...
    );
}

and

php bin/console doctrine:schema:update --force