我刚开始使用ZF2 ......
我想在配置文件中初始化cache
和session
,并且能够在应用程序中使用它(每个地方),或者使用服务管理器,或者......我一直在谷歌搜索数小时没有锁定。 ..在文件中找不到任何有用的东西......
我在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.
那么有效的工厂呢?
所以任何人都可以帮助我吗?
坦克...
答案 0 :(得分: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
选项中获取插件的位置?
答案 1 :(得分:0)
我是从谷歌来到这个话题时使用相同的错误名称,但绝对不同的原因。文件未找到错误可能导致错误。如果出现此错误,请检查配置记录
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
并确保所需文件(在我的情况下为mapper)位于根据上限规则的目录中。