【问题标题】:ZF3 zend-cache error Unable to resolve service "FilesystemCache" to a factoryZF3 zend-cache 错误无法将服务“FilesystemCache”解析为工厂
【发布时间】:2018-08-22 14:37:48
【问题描述】:

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

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

无法将服务“FilesystemCache”解析为工厂;你确定你是在配置时提供的吗?

我在 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 时,会出现以下错误:

[2018 年 10 月 29 日星期一 12:06:13.097747] [php7:warn] [pid 943] [client 127.0.0.1:48824] PHP 警告:file_put_contents(data/cache/module-config-cache.application.config. cache.php):无法打开流:第 65 行的 /var/www/html/roledemo/vendor/zendframework/zend-modulemanager/src/Listener/AbstractListener.php 中没有这样的文件或目录 [2018 年 10 月 29 日星期一 12:06:13.098593] [php7:warn] [pid 943] [client 127.0.0.1:48824] PHP 警告:file_put_contents(data/cache/module-classmap-cache.application.module.cache.php ):无法打开流:第 65 行的 /var/www/html/roledemo/vendor/zendframework/zend-modulemanager/src/Listener/AbstractListener.php 中没有这样的文件或目录 [Mon Oct 29 12:06:13.112886 2018] [php7:error] [pid 943] [client 127.0.0.1:48824] PHP 致命错误:方法 Zend\View\Helper\HeadTitle::__toString() 不得抛出异常,捕获 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

我无法访问任何网址。

可能是我的 php 或 apache 版本?

【问题讨论】:

  • 最近才自己设置。猜你一直在做this?你确定你已经安装了zendframework/zend-cachezendframework/zend-serializer吗?我尝试了同样的方法,它对我来说是开箱即用的。
  • @rkeet 是的,这就是我正在学习的教程。我已经安装了 zendframework/zend-cache 和 zendframework/zend-serializer。你的php版本是什么?它仍然无法在这里工作

标签: zend-framework3 zend-cache


【解决方案1】:

所以我错过了一些东西,这就是为什么它以前不起作用:

  • 创建数据/缓存文件夹并授予其权限 775
  • 创建 public/img/captcha 文件夹并授予权限 775
  • 将模块 Zend\Serializer 和 Zend\Cache 添加到 config/modules.config.php
  • 添加

    'rbac_manager' => [ '断言' => [服务\RbacAssertionManager::class], ],

    到模块/登录/config/module.config.php

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    相关资源
    最近更新 更多