我有一个ViewHelper
并想在以下位置初始化它Module#getViewHelperConfig()
:
<?php
namespace Search;
use statements...
class Module implements
ConfigProviderInterface,
ServiceProviderInterface,
AutoloaderProviderInterface,
ViewHelperProviderInterface {
public function getConfig() ...
public function getAutoloaderConfig() ...
public function getServiceConfig() {
$breakpoint = null;
try {
return array (
'factories' => array(
...
'SearchFormCourseSearchForm' => function ($serviceManager) {
$cacheService = $serviceManager->get('Cache\Model\CityStorage');
$cities = $cacheService->getCities();
$searchForm = new Form\CourseSearchForm($cities);
return $searchForm;
},
)
);
} ...
}
public function getViewHelperConfig() {
$breakpoint = null;
return array(
'factories' => array(
'searhForm' => function($serviceManager) {
$helper = new View\Helper\SearchForm(array('render' => true, 'redirect' => false));
$helper->setViewTemplate('search/search/search-courses');
$searchForm = $serviceManager->get('SearchFormCourseSearchForm');
$helper->setSearchForm($searchForm);
return $helper;
}
)
);
}
但是 ZF 没有给我的工厂打电话。相反,它尝试创建一个新SearchFormCourseSearchForm
实例:
致命错误:未捕获的异常 'Zend\ServiceManager\Exception\ServiceNotFoundException' 与消息 'Zend\ServiceManager\ServiceManager::get 无法在 /var/www/bar/foo/vendor/zendframework/ 中获取或创建 SearchFormCourseSearchForm 的实例zendframework/library/Zend/ServiceManager/ServiceManager.php 在第 456 行
我应该如何使用从Module#getServiceConfig()
创建ViewHelper
in 中获得的服务工厂Module#getViewHelperConfig()
?