是否可以从表单/控制器工厂(任何实现 FactoryInterface 的工厂)访问控制器插件?
我有一个表单工厂,我想根据请求参数设置表单操作,但需要从配置中定义的路由访问 url。
所以在控制器中我会使用 url 控制器插件:
$form->setAttribute('action', $this->url()->fromRoute('appointment.add', array('clientId' => $clientId)));
...我如何在工厂访问它?例如:
class MyFormFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator){
$serviceManager = $serviceLocator->getServiceLocator();
//...snip...
$form = new AddAppointmentForm($client);
$serviceManager->get('ControllerPluginManager');
$url = $controllerPluginManager->get('Url');
die($url->fromRoute('appointment.add', ['clientId' => $clientId]));
return $form;
}