Symfony - Sonata News Bundle

时间:2017-08-02 15:37:28

标签: php symfony config sonata

我在配置Sonata新闻套装时遇到了麻烦。

在能够扩展捆绑包之前,我总是遇到此错误。

InvalidArgumentException in SonataFormatterExtension.php line 71:

SonataFormatterBundle - 无效的默认格式化程序:,可用:[]

这是我的config.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: Sonata\Doctrine\Types\JsonType

    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:     Application\Sonata\UserBundle\Entity\User
    registration:
        confirmation:
            enabled: true

    group:
        group_class:   Application\Sonata\UserBundle\Entity\Group
        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: Application\Sonata\UserBundle\Admin\Model\UserAdmin
            controller: SonataAdminBundle:CRUD
    class:
        user: Application\Sonata\UserBundle\Entity\User
        group: Application\Sonata\UserBundle\Entity\Group

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

有没有人遇到过这个错误?如果是这样,你是如何解决的?

非常感谢!

1 个答案:

答案 0 :(得分:0)

好的,我已经找到了问题。

真正的问题是我没有在config.yml中定义任何默认格式化程序,而且我以错误的顺序调用了bundle。

解决方案是:

{{1}}

再见!