2
A
回答
3
如果你用自己的类扩展形式:
class MyForm extends \Zend\Form\Form
然后,您可以通过在你通过它的构造喜欢的任何变量,并通过表单名称父窗体类这样:
public function __construct($myVar, $myVar2)
{
//do things with my vars
$this->setVar($myVar);
// send name to parent constructor
parent::__construct('myFormName');
}
您可能还需要考虑使用Factory
注入你的依赖,可以在您的Module.php
进行配置,例如:
public function getFormElementConfig()
{
return array(
'factories' => array(
'MyForm' => function (ServiceManager $sm) {
return new \MyNamespace\MyForm($sm->get('someDependancy'));
},
)
);
}
这种形式现在通过任何服务识别类的服务定位:
$serviceLocator->get('FormElementManager')->get('MyForm');
具备通过工厂注入的依赖关系。
'$ form-> setAttribute'? – raina77ow 2014-09-04 20:28:02