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

Posted

技术标签:

【中文标题】PHP 致命错误:未捕获的异常“Symfony\\Component\\Yaml\\Exception\\ParseException”【英文标题】:PHP Fatal error: Uncaught exception 'Symfony\Component\Yaml\Exception\ParseException'PHP 致命错误:未捕获的异常“Symfony\Component\Yaml\Exception\ParseException” 【发布时间】:2017-12-11 17:44:03 【问题描述】:

我在使用 symfony 2.8 时遇到了这个错误,可能是 config.yml 中的错误,请帮助我解决这个问题并感谢高级

FileLoader.php 第 133 行中的 FileLoaderLoadException: 文件“/var/www/html/authenti/app/config/config.yml”在 /var/www/html/authenti/app/config/config.yml 中不包含有效的 YAML(从“/ var/www/html/authenti/app/config/config_dev.yml")。

代码 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

【问题讨论】:

嗯,这可能只是复制/粘贴问题,但所有部分(导入:、框架:等)都需要从最左边的列开始。您还应该在所有字符串周围使用单引号,尤其是使用 %parameter%。我怀疑您是否真的在进行任何测试之前就开始使用这些文件?可能想要回滚到以前的工作版本。 【参考方案1】:

尽量缩进,我看到这个例子来解决:

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

更正:

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

【讨论】:

很高兴为您提供帮助! 现在当我访问localhost/authenti/web/app_dev.php/login_check 我有这个结果,imgur.com/a/Mqs8E,这是真正的结果还是这是错误??!请帮我解决这个问题

以上是关于PHP 致命错误:未捕获的异常“Symfony\Component\Yaml\Exception\ParseException”的主要内容,如果未能解决你的问题,请参考以下文章

parse-php-sdk 致命错误:未捕获的异常 'Parse\ParseException' 带有消息 'unauthorized'

致命错误:未捕获的异常“PDOException”,带有消息“SQLSTATE [42000]:语法错误或访问冲突 PHP 和 PDO

致命错误:第 19 行的 C:\xampp\htdocs\register.php 中抛出未捕获的异常“PDOException”

PHP 异常处理 总出现致命错误 无法捕获异常

PHP/MongoDB 错误:未捕获的异常“MongoCursorException”

致命错误:未捕获的异常 PAYPAL