LauraEld
LauraEld

Reputation: 349

Symfony 3 - Sonata Aplication Media Bundle error

I was following the official documentation to install Sonata Media Bundle, I think it worked until the step when I use this command:

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

Then I add new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(), to AppKernel.php.

After these steps, I try to enter to mi admin (localhost:8000/admin) but throws this error:

Attempted to load class "ApplicationSonataMediaBundle" from namespace "Application\Sonata\MediaBundle". Did you forget a "use" statement for another namespace?

I try to execute php bin/console doctrine:schema:create (or update) and the error continues:

ubuntu@ubuntu-xenial:/workdir/Testing$ php bin/console doctrine:schema:update --force
PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "ApplicationSonataMediaBundle" from namespace "Application\Sonata\MediaBundle".
Did you forget a "use" statement for another namespace? in /workdir/Testing/app/AppKernel.php:32
Stack trace:
#0 /workdir/Testing/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(450): AppKernel->registerBundles()
#1 /workdir/Testing/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 /workdir/Testing/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(137): Symfony\Component\HttpKernel\Kernel->boot()
#3 /workdir/Testing/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(124): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()
#4 /workdir/Testing/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(90): Symfony\Bundle\FrameworkBundle\Console\Applica in /workdir/Testing/app/AppKernel.php on line 32

I verified that the routes were correct and followed steps just like the documentation, I've been looking for answers over the internet and found anything. Please help!

I tried to execute php bin/console sonata:easy-extends:generate --dest=src SonataMediaBundle without --dest=src to place folder in app/ but the error continues...

My config.yml according to the doc:

doctrine:
  dbal:
      driver: pdo_mysql
      host: '%database_host%'
      port: '%database_port%'
      dbname: '%database_name%'
      user: '%database_user%'
      password: '%database_password%'
      charset: UTF8
      types:
             json: Sonata\Doctrine\Types\JsonType
      # if using pdo_sqlite as your database driver:
      #   1. add the path in parameters.yml
      #     e.g. database_path: "%kernel.project_dir%/var/data/data.sqlite"
      #   2. Uncomment database_path in parameters.yml.dist
      #   3. Uncomment next line:
      #path: '%database_path%'

  orm:
      auto_generate_proxy_classes: '%kernel.debug%'
      naming_strategy: doctrine.orm.naming_strategy.underscore
      auto_mapping: true
      mappings:
           ApplicationSonataMediaBundle: ~
           SonataMediaBundle: ~

sonata_media:
  # 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}

  cdn:
      server:
          path: /uploads/media # http://media.sonata-project.org/

  filesystem:
      local:
          directory:  "%kernel.root_dir%/../web/uploads/media"
          create:     false

And my routing.yml:

gallery:
   resource: '@SonataMediaBundle/Resources/config/routing/gallery.xml'
   prefix: /media/gallery

media:
   resource: '@SonataMediaBundle/Resources/config/routing/media.xml'
   prefix: /media

EDIT:

I think the problem is with Easy-Extends because I tried to install Classification Bundle and the same happens, does current Symfony version support Easy-Extends? Maybe because Sonata User Bundle is not compatible with current version (I tried this too)...

EDIT 2:

My composer.json file:

{
    "name": "vagrant/testing",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "AppBundle\\": "src/AppBundle"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        },
        "files": [
            "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
        ]
    },
    "require": {
        "php": ">=5.5.9",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.5",
        "friendsofsymfony/user-bundle": "^2.0",
        "gedmo/doctrine-extensions": "^2.4",
        "incenteev/composer-parameter-handler": "^2.0",
        "pixassociates/sortable-behavior-bundle": "^1.3",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^3.0.2",
        "sonata-project/admin-bundle": "^3.20",
        "sonata-project/doctrine-orm-admin-bundle": "^3.1",
        "sonata-project/easy-extends-bundle": "^2.2",
        "sonata-project/media-bundle": "^3.6",
        "stof/doctrine-extensions-bundle": "^1.2",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.3.10",
        "symfony/symfony": "3.3.*",
        "twig/twig": "^1.0||^2.0",
        "vich/uploader-bundle": "^1.6"
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    },
    "scripts": {
        "symfony-scripts": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-install-cmd": [
            "@symfony-scripts"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ]
    },
    "config": {
        "sort-packages": true
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-bin-dir": "bin",
        "symfony-var-dir": "var",
        "symfony-web-dir": "web",
        "symfony-tests-dir": "tests",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": null
    }
}

Upvotes: 1

Views: 1358

Answers (1)

Jakub Matczak
Jakub Matczak

Reputation: 15656

You need to add autoloader definition in your composer.json in a similar way that there is already for AppBundle.

As I understand, the new bundle is generated under path src/Application/Sonata/MediaBundle so it would be:

"autoload": {
    "psr-4": {
        "AppBundle\\": "src/AppBundle"
        "Application\Sonata\MediaBundle\\": "src/Application/Sonata/MediaBundle"
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},

Upvotes: 6

Related Questions