我正在关注官方documentation安装Sonata Media Bundle,我认为它一直有效,直到我使用此命令的步骤:
php bin/console sonata:easy-extends:generate --dest=src SonataMediaBundle
然后我将new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
添加到AppKernel.php。
完成这些步骤后,我尝试进入mi admin(localhost:8000 / admin),但抛出此错误:
尝试从名称空间“Application \ Sonata \ MediaBundle”加载类“ApplicationSonataMediaBundle”。 您是否忘记了另一个命名空间的“use”语句?
我尝试执行php bin/console doctrine:schema:create
(或更新),错误仍在继续:
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
我确认路线是正确的,并按照文档的步骤进行操作,我一直在寻找互联网上的答案,并找到了任何东西。请帮忙!
我尝试在没有php bin/console sonata:easy-extends:generate --dest=src SonataMediaBundle
的情况下执行--dest=src
将文件夹放在app /中,但错误仍在继续......
我的config.yml根据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
我的routing.yml:
gallery:
resource: '@SonataMediaBundle/Resources/config/routing/gallery.xml'
prefix: /media/gallery
media:
resource: '@SonataMediaBundle/Resources/config/routing/media.xml'
prefix: /media
修改
我认为问题出在Easy-Extends上,因为我尝试安装Classification Bundle并且同样的情况发生,当前的Symfony版本是否支持Easy-Extends?也许是因为Sonata User Bundle与当前版本不兼容(我也试过了)......
编辑2:
我的composer.json文件:
{
"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
}
}
答案 0 :(得分:5)
您需要在composer.json中添加自动加载器定义,其方式与AppBundle
类似。
据我所知,新的包是在路径src/Application/Sonata/MediaBundle
下生成的,所以它将是:
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
"Application\Sonata\MediaBundle\\": "src/Application/Sonata/MediaBundle"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},