【问题标题】:Symfony Sonata-CacheBundle configuration errorSymfony Sonata-CacheBundle 配置错误
【发布时间】:2014-10-04 09:17:30
【问题描述】:

我安装了带有 Corebundle、Blockbundle 和 Adminbundle 的 Symfony CMF (se1.1),所有这些都可以正常工作。现在我安装了 Sonata Cachebundle(Sonata Pagebundle 需要),网站现在显示这个错误:

InvalidConfigurationException:“sonata_cache.caches”下无法识别的选项“symfony”

(我使用 Composer 来安装这个包。)

这里是我关于 Cachebundle 的配置文件列表;

app/AppKernel.php

new Sonata\CacheBundle\SonataCacheBundle(),

app/autoload.php

<?php

use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;

/**
* @var ClassLoader $loader
*/
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('Sonata', __DIR__);

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

app/config/config.yml

sonata_cache:
  caches:
  esi:
      token: an unique security key # a random one is generated by default
      servers:
          - varnishadm -T 127.0.0.1:2000 {{ COMMAND }} "{{ EXPRESSION }}"

  ssi:
      token: an unique security key # a random one is generated by default

  mongo:
      database:   cache
      collection: cache
      servers:
          - {host: 127.0.0.1, port: 27017, user: username, password: pASS'}
          - {host: 127.0.0.2}

  memcached:
      prefix: test     # prefix to ensure there is no clash between instances
      servers:
          - {host: 127.0.0.1, port: 11211, weight: 0}

  predis:
      servers:
          - {host: 127.0.0.1, port: 6379, database: 42}

  apc:
      token:  s3cur3   # token used to clear the related cache
      prefix: test     # prefix to ensure there is no clash between instances
      servers:
          - { domain: kooqit.local, ip: 127.0.0.1, port: 80}

  symfony:
      token: s3cur3 # token used to clear the related cache
      php_cache_enabled: true # Optional (default: false), clear APC or PHP OPcache
      types: [mytype1, mycustomtype2] # Optional, you can restrict allowed cache types
      servers:
          - { domain: kooqit.local, ip: 127.0.0.1, port: 80}

app/config/routing.yml

sonata_cache_cache:
  resource: '@SonataCacheBundle/Resources/config/routing/cache.xml'
  prefix: / 

我希望有人能指出这里到底出了什么问题..

【问题讨论】:

    标签: php symfony


    【解决方案1】:

    您的配置有一些错误:caches 之前的缩进和其他应该是四个空格,工作示例:

      sonata_cache:
          caches:
            esi:
                token: an unique security key # a random one is generated by default
                servers:
                    - varnishadm -T 127.0.0.1:2000 {{ COMMAND }} "{{ EXPRESSION }}"
    
            ssi:
                token: an unique security key # a random one is generated by default
    
            mongo:
                database:   cache
                collection: cache
                servers:
                    - {host: 127.0.0.1, port: 27017, user: username, password: pASS'}
                    - {host: 127.0.0.2}
    
            memcached:
                prefix: test     # prefix to ensure there is no clash between instances
                servers:
                    - {host: 127.0.0.1, port: 11211, weight: 0}
    
            predis:
                servers:
                    - {host: 127.0.0.1, port: 6379, database: 42}
    
            apc:
                token:  s3cur3   # token used to clear the related cache
                prefix: test     # prefix to ensure there is no clash between instances
                servers:
                    - { domain: kooqit.local, ip: 127.0.0.1, port: 80}
    
            symfony:
                token: s3cur3 # token used to clear the related cache
                php_cache_enabled: true # Optional (default: false), clear APC or PHP OPcache
                types: [mytype1, mycustomtype2] # Optional, you can restrict allowed cache types
                servers:
                    - { domain: kooqit.local, ip: 127.0.0.1, port: 80}
    

    试试吧!!!当然,一如既往地运行命令cache:clearcache:warmup

    【讨论】:

    • Cache:clear return with --> {Unrecognized options "esi, ssi, mongo, memcached, predis, apc, symfony" under "sonata_cache"}
    • 抱歉,我在缩进代码时犯了一个错误,我已修复,当您遇到此类问题时,请尝试手动删除缓存
    • Indetation 已修复,但返回相同的错误消息 --> {Unrecognized options "symfony" under "sonata_cache.caches"}
    • 尝试评论那些行,我不知道那些是什么所以我根本不使用
    • 我注释掉了:'symfony',然后是'apc'。然后是“predis”,然后是“memcached”,然后是“mongo”。在所有这些错误消失之后......(
    【解决方案2】:

    最终的答案其实很简单(回头看总是这样)。

    在 app/config/config.yml 文件中(显然)不允许有在 Symfony CMF 中未正确配置的“选项”。

    如果这个功能没有在 Symfony CMF 中正确安装和配置,像 'mongo' 这样的选项会产生错误消息(听起来合乎逻辑)。

    所以,我的建议(感谢@ReynierPM)确实是注释掉那些给出错误的部分。但请注意,如果您稍后将使用完整的“mongo”功能,则必须取消注释该特定部分才能为其激活缓存。

    【讨论】:

    • 很高兴您解决了这个问题,您会接受我的回答还是接受您的回答?
    • 由于我的回答是基于你的回答,所以选择有点困难。从其他用户的学习角度来看,我将选择我的答案,因为它包含更多解释。但正如我的回答中明确指出的那样,功劳归你所有,因为它基于你的回答..
    猜你喜欢
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 2014-12-31
    • 2019-01-12
    • 1970-01-01
    相关资源
    最近更新 更多