我在配置Sonata新闻包时遇到问题。
在能够扩展捆绑包之前,我总是收到此错误。
InvalidArgumentException in SonataFormatterExtension.php line 71:
Sonata格式化程序捆绑包 - 无效的默认格式化程序 : , 可用 : []
这是我的配置.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: sonata_news.yml }
- { resource: "@HomeBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
translator: { fallbacks: [fr] }
secret: '%secret%'
router:
resource: '%kernel.root_dir%/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: '%locale%'
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
types:
json: SonataDoctrineTypesJsonType
orm:
entity_managers:
default:
mappings:
ApplicationSonataUserBundle: ~
SonataUserBundle: ~
FOSUserBundle: ~
SonataMediaBundle: ~
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: ApplicationSonataUserBundleEntityUser
registration:
confirmation:
enabled: true
group:
group_class: ApplicationSonataUserBundleEntityGroup
group_manager: sonata.user.orm.group_manager
service:
user_manager: sonata.user.orm.user_manager
sonata_user:
security_acl: true
manager_type: orm
admin:
user:
class: ApplicationSonataUserBundleAdminModelUserAdmin
controller: SonataAdminBundle:CRUD
class:
user: ApplicationSonataUserBundleEntityUser
group: ApplicationSonataUserBundleEntityGroup
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata_media:
db_driver: doctrine_orm
default_context: default
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}
news:
providers:
- sonata.media.provider.dailymotion
- sonata.media.provider.youtube
- sonata.media.provider.image
formats:
small: { width: 150 , quality: 95}
big: { width: 500 , quality: 90}
cdn:
server:
path: /uploads/media
filesystem:
local:
directory: "%kernel.root_dir%/../web/uploads/media"
create: false
这是我的sonata_news.yml
sonata_news:
title: Sonata Project
link: https://sonata-project.org
description: Cool bundles on top of Symfony2
salt: 'secureToken'
permalink_generator: sonata.news.permalink.date # sonata.news.permalink.collection
comment:
notification:
emails: [email@example.org, email2@example.org]
from: no-reply@sonata-project.org
template: 'SonataNewsBundle:Mail:comment_notification.txt.twig'
doctrine:
orm:
entity_managers:
default:
#metadata_cache_driver: apc
#query_cache_driver: apc
#result_cache_driver: apc
mappings:
# ApplicationSonataNewsBundle: ~
SonataNewsBundle: ~
最后是 sonata_formatter.yml
sonata_formatter:
formatters:
markdown:
service: sonata.formatter.text.markdown
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
text:
service: sonata.formatter.text.text
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
rawhtml:
service: sonata.formatter.text.raw
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
richhtml:
service: sonata.formatter.text.raw
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
有没有人遇到过这个错误?如果是这样,你是如何解决的?
多谢!
好的,我已经解决了问题。
真正的问题是我没有在我的config.yml中定义任何默认格式化程序,并且我以错误的顺序调用了捆绑包。
解决方案是:
new IvoryCKEditorBundleIvoryCKEditorBundle(),
new KnpBundleMarkdownBundleKnpMarkdownBundle(),
new SonataFormatterBundleSonataFormatterBundle(),
再见!