【发布时间】:2023-03-20 11:49:01
【问题描述】:
我在这里创建自定义元素:ZF2Docs: Advanced use of Forms
1.在Application/Form/Element/CustomElement.php中创建CustomElement类
2.添加到我的Module.php函数
public function getFormElementConfig()
{
return array(
'invokables' => array(
'custom' => 'Application\Form\Element\CustomElement',
),
);
}
如果我使用 FQCN,它可以正常工作:
$form->add(array(
'type' => 'Application\Form\Element\CustomElement',
'name' => 'myCustomElement'
));
但如果我使用短名称:
$form->add(array(
'type' => 'Custom',
'name' => 'myCustomElement'
));
抛出异常:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create
an instance for Custom
【问题讨论】:
-
@AydinHassan 这到底有什么关系? :D @Ildar,只是为了确保 Elements 类被称为
CustomElement而不是Custom? -
@Sam,是的,Elements 类叫做 CustomElement
-
我已经更改了可调用对象中 customElement 上的自定义,它可以正常工作。
标签: zend-framework zend-framework2