FormElementManager
正在扩展自
ServiceManager
因此,您必须将其配置为与service manager相同。这里有一个例子
class MyModule {
function getConfig(){
return [
/* other configs */
'form_elements' => [ // main config key for FormElementManager
'factories' => [
\Application\Fieldset\Outline::class => \Application\Fieldset\Factory\OutlineFactory::class
]
]
/* other configs */
];
}
}
使用此配置,当您调用
\Application\Fieldset\Outline::class
,
\Application\Fieldset\Factory\OutlineFactory::class
将由触发
FormElementManager
。一切都一样
服务经理
。您将通过service manager调用您的字段集as;
$container->get('FormElementManager')->get(\Application\Fieldset\Outline::class);
您还可以通过以下方式在表单/字段集中调用它
getFormFactory
方法
function init() { // can be construct method too, nothing wrong
$this->getFormFactory()->getFormElementManager()->get(\Application\Fieldset\Outline::class);
}
当然,您可以在工厂支持的表单扩展中使用它的名称。
但是
如果您通过
new
关键字,将不会触发您的工厂。