PHP致命错误:未捕获异常'Symfony \ Component \ Yaml \ Exception \ ParseException'

时间:2017-07-07 12:17:09

标签: symfony symfony-2.1

当我使用symfony 2.8时,我有这个bug,也许在config.yml中有错误,请帮我解决这个问题并感谢高级

  

FileLoader.php第133行中的FileLoaderLoadException:   文件“/var/www/html/authenti/app/config/config.yml”在/var/www/html/authenti/app/config/config.yml中不包含有效的YAML(正在从“/”导入无功/网络/ HTML / authenti /应用/配置/ config_dev.yml“)。

code config.yml:

imports:
        - { resource: parameters.yml }
        - { resource: security.yml }
        - { resource: 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: ['%locale%'] }
        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
            # if using pdo_sqlite as your database driver:
            #   1. add the path in parameters.yml
            #     e.g. database_path: '%kernel.root_dir%/data/data.db3'
            #   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

    # Swiftmailer Configuration
    swiftmailer:
        transport: '%mailer_transport%'
        host: '%mailer_host%'
        username: '%mailer_user%'
        password: '%mailer_password%'
        spool: { type: memory }

    imports:
        // ...
        - { resource: security.yml }
    // ...
    framework:
        // ...
        csrf_protection: ~
        form: ~
        session:
            handler_id: ~
        // ...
    fos_user:
        db_driver: orm
        firewall_name: main
        user_class: AppBundle\Entity\User
    lexik_jwt_authentication:
        private_key_path: %jwt_private_key_path%
        public_key_path:  %jwt_public_key_path%
        pass_phrase:      %jwt_key_pass_phrase%
        token_ttl:        %jwt_token_ttl%
    // ...
    dunglas_api:
        title:       "%api_name%"
        description: "%api_description%"
        enable_fos_user: true
    nelmio_cors:
        defaults:
            allow_origin:   ["%cors_allow_origin%"]
            allow_methods:  ["POST", "PUT", "GET", "DELETE", "OPTIONS"]
            allow_headers:  ["content-type", "authorization"]
            expose_headers: ["link"]
            max_age:       3600
        paths:
            '^/': ~

的routing.yml:

app:
    resource: '@AppBundle/Controller/'
    type: annotation

api:
    resource: "."
    type:     "api"
    prefix: "/api"

api_login_check:
    path: "/login_check"

parameters.yml.dist:

# This file is a "template" of what your parameters.yml file should look like
    # Set parameters here that may be different on each deployment target of the app, e.g. development, staging, production.
    # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
    parameters:
        database_host: 127.0.0.1
        database_port: ~
        database_name: symfony
        database_user: root
        database_password: ~
        # You should uncomment this if you want to use pdo_sqlite
        #database_path: "%kernel.root_dir%/data.db3"

        mailer_transport: smtp
        mailer_host: 127.0.0.1
        mailer_user: ~
        mailer_password: ~

        jwt_private_key_path: %kernel.root_dir%/var/jwt/private.pem
        jwt_public_key_path:  %kernel.root_dir%/var/jwt/public.pem
        jwt_key_pass_phrase : 'test'
        jwt_token_ttl:        86400

        cors_allow_origin: http://localhost:9000

        api_name:          Your API name
        api_description:   The full description of your API


        # A secret key that's used to generate certain security-related tokens
        secret: ThisTokenIsNotSoSecretChangeIt

1 个答案:

答案 0 :(得分:1)

尝试缩进,我看到这例如修复:

imports:
        - { resource: parameters.yml }
        - { resource: security.yml }
        - { resource: services.yml }

修正:

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }