Zend Framework 2 Service Manager 配置方法
2024-11-14 18:13:39 203人阅读
我们通常会把Service Manager配置在两个地方
1.module.config.php
2.Module.php
不同的service manager 类型有不同的配置方法
Application services
Manager | Application services |
Manager class | Zend\ServiceManager\ServiceManager |
Config key | service_manager |
Module method | getServiceConfig() |
Module interface | ServiceProviderInterface |
moduel.config.php
return array (
‘service_manager‘ => array (
‘factories‘ => array (
‘translator‘ => ‘Zend\I18n\Translator\TranslatorServiceFactory‘ ,
‘Application\Header\Navigation‘ => ‘Application\Navigation\HeaderNavigationFactory‘
),
),
);
|
Moduel.php
class Module{
public function getServiceConfig(){
return array (
‘invokables‘ => array ( ),
);
}
}
|
Controllers
Manager | Controllers |
Manager class | Zend\Mvc\Controller\ControllerManager |
Config key | controllers |
Module method | getControllerConfig() |
Module interface | ControllerProviderInterface |
Service name | ControllerLoader |
module.config.php
return array (
‘controllers‘ => array (
‘invokables‘ => array (
‘Application\Controller\Index‘ => ‘Application\Controller\IndexController‘ ,
)
),
);
|
Module.php
class Module{
public function getControllerConfig()
{
return array (
‘invokables‘ => array (
‘Application\Controller\Index‘ => ‘Application\Controller\IndexController‘ ,
),
);
}
}
|
Controller plugins
Manager | Controller plugins |
Manager class | Zend\Mvc\Controller\PluginManager |
Config key | controller_plugins |
Module method | getControllerPluginConfig() |
Module interface | ControllerPluginProviderInterface |
Service name | ControllerPluginManager |
module.config.php
return array (
‘controller_plugins‘ => array (
‘factories‘ => array (
‘MyModule\Controller\Plugin\Foo‘ => function ( $sm ) {
$plugin = new Plugin\Foo;
$cache = $sm ->get( ‘my-cache‘ );
$plugin ->setCache( $cache );
return $plugin ;
},
),
),
);
|
Module.php
class Module{
public function getControllerPluginConfig()
{
return array (
‘invokables‘ => array (
),
);
}
}
|
View helpers
Manager | View helpers |
Manager class | Zend\View\HelperPluginManager |
Config key | view_helpers |
Module method | getViewHelperConfig() |
Module interface | ViewHelperProviderInterface |
Service name | ViewHelperManager |
module.config.php
return array (
‘view_helpers‘ => array (
‘factories‘ => array (
‘ApplicationHelper‘ => function ( $helperPluginManager ) {
}
)
),
);
|
Module.php
class
Module{
public
function
getViewHelperConfig()
{
return
array
(
‘factories‘
=>
array
(
‘ApplicationHelper‘
=>
function
(
$helperPluginManager
) {
}
),
);
}
}
Zend Framework 2 Service Manager 配置方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。