我知道如何为ViewModel设置特定模板.但是,在ViewModel中设置模板之前,如何检查当前模板路径堆栈中是否存在不同的模板?我的想法是,我可以重复使用单个操作来基于查询参数呈现视图.我想首先检查,如果视图不存在,那么我可以将响应状态代码设置为404而不是通用服务器错误消息.
我正在尝试使用工厂创建一个新的Controller插件来注入依赖项.
public function createService(ServiceLocatorInterface $serviceLocator) {
$services = $serviceLocator->getServiceLocator();
/** @var \Zend\Mvc\Controller\PluginManager */
$plugin = new MyPlugin();
if ($services->has('my_service')) {
$plugin->setService($services->get('my_service'));
}
return $plugin;
}
Run Code Online (Sandbox Code Playgroud)
问题是$服务找不到'my_service'
我在服务管理器中添加了正确的配置
'services' => array(
'invokables' => array(
'my_service' => 'Application\Service\MyService'
)
),
'controller_plugins' => array(
'factories' => array(
'my_plugin' => 'Application\Controller\Plugin\Factory\MyPlugin'
)
)
Run Code Online (Sandbox Code Playgroud)
我的想法是PluginManager中的一个错误,它没有正确地注入服务管理器.