【问题标题】:creating and managing cache and session in Zend Framwork 2在 Zend Framework 2 中创建和管理缓存和会话
【发布时间】:2012-11-19 11:38:45
【问题描述】:

我刚开始使用 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. 那么有效的工厂是什么? 所以任何人都可以在这里帮助我吗? 坦克...

【问题讨论】:

  • 这没有多大意义。 session是自动启动的,你不用管它,要改的话,在php.ini里改
  • ????我的问题在哪里说明了如何开始会话?
  • "我要初始化缓存和会话"

标签: session caching config zend-framework2


【解决方案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 的插件?

【讨论】:

【解决方案2】:

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

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

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

【讨论】:

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