創建自定義元素喜歡這裏:ZF2Docs: Advanced use of Forms當我在Zend Framework 2中創建自定義表單元素時,爲什麼不使用短名稱?
1.創建CustomElement類應用程序/表格/元/ CustomElement.php
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,爲了確保元素類被稱爲'CustomElement'而不是'Custom'? – Sam 2013-04-09 06:07:41
@Sam,是的,元素類被稱爲CustomElement – Ildar 2013-04-09 06:29:22
我已經改變了invokeables中的customElement自定義,它的工作原理。 – Ildar 2013-04-09 07:01:52