【发布时间】:2014-03-28 17:27:34
【问题描述】:
我为这个问题苦苦挣扎了几天,但仍然没有找到问题所在。
这是我在 application.config.php 中的配置段:
// Initial configuration with which to seed the ServiceManager.
// Should be compatible with Zend\ServiceManager\Config.
'service_manager' => array(
'abstract_factories' => array(
'Zend\Log\LoggerAbstractServiceFactory',
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
)
),
'log' => array(
'Log\App' => array(
'writers' => array(
array(
'name' => 'stream',
'priority' => 1000,
'options' => array(
'stream' => 'data/logs/app.log'
)
)
)
)
)
我尝试在我的控制器中获取服务实例:
$logger = $this->getServiceLocator()->get('Log\\App');
并抛出异常:
An error occurred
An error occurred during execution; please try again later.
Additional information:
Zend\ServiceManager\Exception\ServiceNotFoundException
File:
/var/openresty/html/skeleton-zf2/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:529
Message:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Log\App
更新 感谢您的帮助ocramius
我将段移动到module.config.php,这次抛出异常:
Zend\ServiceManager\Exception\ServiceNotCreatedException
File:
/var/openresty/html/skeleton-zf2/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:1070
Message:
An abstract factory could not create an instance of applicationweb(alias: Application\Web).
【问题讨论】:
-
你能验证
Zend\Log\LoggerAbstractServiceFactory#canCreateServiceWithName()是否被调用?另外,你的意思是application.config.php还是config/autoload中的什么?
标签: php logging zend-framework2