ZF3 zend-cache 错误 Unable to resolve service "FilesystemCache" to a factory

ZF3 zend-cache error Unable to resolve service "FilesystemCache" to a factory

我正在尝试将 zend-cache 与 zend-rbac 一起使用。

zend-rbac 没问题,但是当我尝试添加 zend-cache 时,我收到了这条消息:

Unable to resolve service "FilesystemCache" to a factory; are you certain you provided it during configuration?

我在global.php的缓存配置是这样的:

// Cache configuration.
'caches' => [
    'FilesystemCache' => [
        'adapter' => [
            'name'    => Filesystem::class,
            'options' => [
                // Store cached data in this directory.
                'cache_dir' => './data/cache',
                // Store cached data for 1 hour.
                'ttl' => 60*60*1
            ],
        ],
        'plugins' => [
            [
                'name' => 'serializer',
                'options' => [                        
                ],
            ],
        ],
    ],
],

在我的 RbacManagerFactory 中,我这样称呼它:

$cache = $container->get('FilesystemCache');

我已经尝试在我的模块中配置 FilesystemService,如下所示:

'service_manager' => [
    'factories' => [
        \Zend\Cache\Storage\Adapter\FilesystemService::class => InvokableFactory::class,
    ],
],

但是没用

我需要配置更多的东西吗?

编辑 2018-10-29

当我尝试 运行 时 sample 它给出了这个错误:

[Mon Oct 29 12:06:13.097747 2018] [php7:warn] [pid 943] [client 127.0.0.1:48824] PHP Warning: file_put_contents(data/cache/module-config-cache.application.config.cache.php): failed to open stream: No such file or directory in /var/www/html/roledemo/vendor/zendframework/zend-modulemanager/src/Listener/AbstractListener.php on line 65 [Mon Oct 29 12:06:13.098593 2018] [php7:warn] [pid 943] [client 127.0.0.1:48824] PHP Warning: file_put_contents(data/cache/module-classmap-cache.application.module.cache.php): failed to open stream: No such file or directory in /var/www/html/roledemo/vendor/zendframework/zend-modulemanager/src/Listener/AbstractListener.php on line 65 [Mon Oct 29 12:06:13.112886 2018] [php7:error] [pid 943] [client 127.0.0.1:48824] PHP Fatal error: Method Zend\View\Helper\HeadTitle::__toString() must not throw an exception, caught Zend\I18n\Exception\ExtensionNotLoadedException: Zend\I18n\Translator component requires the intl PHP extension in /var/www/html/roledemo/module/Application/view/layout/layout.phtml on line 0

而且我无法访问任何 URL。

会不会是我的 php 或 apache 版本?

所以我遗漏了一些东西,这就是它之前不起作用的原因:

  • 创建data/cache文件夹并赋予权限775
  • 创建public/img/captcha文件夹并赋予权限775
  • 将模块 Zend\Serializer 和 Zend\Cache 添加到 config/modules。config.php
  • 添加

    'rbac_manager' => [ 'assertions' => [Service\RbacAssertionManager::class], ],

    到module/Login/config/module.config.php

  • 而且,如果您是按照文本阅读,而不是下载代码: 在 src/Service/RbacManager.php 第 72
  • 行中将 $result 设置为 false