1

我刚开始使用 ZF2 ...我想初始化cachesession在配置文件中使用它,并且能够使用服务管理器在应用程序(每个地方)中使用它,或者......我已经在谷歌搜索了几个小时而没有锁定.. . 在文档中找不到任何有用的东西并且...

我在module.config.php(应用程序模块)中试过这个:

'service_manager' => array(
        'factories' => array(
            'cache' => '\Zend\Cache\StorageFactory',
        ),
    ),
    'cache' => array(
        'storage' => array(
            'adapter' => 'Filesystem',
            'options' => array(
                'cache_dir' => __DIR__ . '/../../../data/cache'
            ),
        ),
        'plugins' => array('WriteControl', 'IgnoreUserAbort'),
        'options' => array(
            'removeOnFailure' => true,
            'exitOnAbort' => true,
            'ttl' => 100
        ),
    ),

我收到了这个错误:While attempting to create cache(alias: cache) an invalid factory was registered for this instance type. 那么有效的工厂是什么?所以任何人都可以在这里帮助我吗?坦克...

4

2 回答 2

1

使用闭包作为工厂,因为Zend\Cache\StorageFactory没有实现Zend\ServiceManager\FactoryInterface

'service_manager' => array(
    'factories' => array(
        'cache' => function () {
            return Zend\Cache\StorageFactory::factory(array(
                'storage' => array(
                    'adapter' => 'Filesystem',
                    'options' => array(
                        'cache_dir' => __DIR__ . '/../../../data/cache',
                        'ttl' => 100
                    ),
                ),
                'plugins' => array(
                    'IgnoreUserAbort' => array(
                        'exitOnAbort' => true
                    ),
                ),
            ));
        },
    ),
)

顺便提一句。清理你的缓存配置,你从哪里得到插件WriteControl和选项removeOnFailure

于 2012-11-21T21:27:32.360 回答
0

我从谷歌来到这个主题,错误名称相同,但原因肯定不同。错误可能是由找不到文件错误引起的。如果您收到此错误,请检查您的配置记录

'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),

并确保所需文件(在我的情况下为映射器)根据上层规则位于目录中。

于 2013-05-24T07:42:17.090 回答