我遇到了zf2表单注释的麻烦。问题是: a有一个带有简单元素注解的表单,但我需要在表单注释中添加一个字段集。该字段集包含一些文本元素。直到这里,我没有任何问题使用annotationBiulder和CreateForm方法在控制器中创建表单。 但是,如果我想将某些参数传递给构造函数fieldset,则无法使用注释调用fieldset。 有没有解决方案?窗体构造函数和注释biulder
0
A
回答
0
使用的字段集
- @annotation \ ComposedObject( “命名空间/实体/ myEntity所”)
看到http://devblog.x2k.co.uk/using-the-composedobject-zend-framework-2-form-annotation/
0
我不认为这是我的问题的解决方案。 我有注释和一个里面有一个名为MyFieldset
/**
* @Form\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")
* @Form\Name("MyForm")
*/
class MyForm {
/**
* @Form\Required(false)
* @Form\Attributes({"type":"hidden"})
*/
protected $id;
/**
* @Form\Required(true)
* @Form\Type("Zend\Form\Element\Text")
* @Form\Options({"label":"Title"})
* @Form\Filter({"name":"StringTrim"})
* @Form\Filter({"name":"StripTags"})
* @Form\Validator({"name": "StringLength", "options": {"min":3, "max": 250}})
*/
protected $title;
/**
* @Form\Required(true)
* @Form\Type("Zend\Form\Element\Text")
* @Form\Options({"label":"Description"})
* @Form\Filter({"name":"StringTrim"})
* @Form\Filter({"name":"StripTags"})
*/
protected $description;
/**
* @Form\Required(false)
* @Form\Type("Application\Form\MyFieldset")
* @Form\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")
* @Form\Options({"label":"Translations"})
* @Form\Filter({"name":"StringTrim"})
* @Form\Filter({"name":"StripTags"})
*/
protected $translations;
的MyFieldset类有一个构造需要,我需要用更换为一个循环的目标参数的自定义字段集建立了一个表格。我尝试了各种可能的解决方案来解决这个问题,例如使用Service Locator注入实现ServiceLocatorAwareInterface。
class MyFieldset extends Fieldset implements InputFilterProviderInterface {
protected $obj;
public function __construct(SomeObject $obj) {
parent::__construct('myfieldset');
$this->obj = $em;
}
public function init() {
for ($i=0;$i<2;$i++) {
$object = new Element\Text();
$object
->setAttribute('name', 'myfieldset_'.$i)
->setOptions(array('label' => 'Myfieldset'))
;//->setAttribute('required', true);
$this->add($object);
}
}
public function getInputFilterSpecification() {
return array(
/* 'name' => $this->getName(),
'required' => true,
'filters' => array(
array('name' => 'Zend\Filter\StringTrim'),
array('name' => 'Zend\Filter\StringToLower'),
),
'validators' => array(
array(
'name' => 'String'
)
), */
);
相关问题
- 1. Symfony窗体和实体构造函数
- 2. c#构造函数注入和构造函数重载
- 3. asp.net web窗体构造函数?
- 4. 窗体构造函数中的行为
- 5. Spring云数据流@EnableBinding注释中断构造函数注入
- 6. 在Spring中通过注释向构造函数注入参数
- 7. 从子窗体symfony调用父窗体构造函数
- 8. 使用注释向构造函数注入bean的集合
- 9. Spring DI:使用注释在构造函数中注入FileInputStream
- 10. CGLIB,弹簧和注入构造函数
- 11. Dagger 2.0构造函数注入和Singleton
- 12. AndroidAnnotations和构造函数注入
- 13. LightInject:构造函数注入和IDisposable
- 14. OOP,依赖注入和构造函数
- 15. JAXB构造函数注入
- 16. Unity构造函数注入
- 17. TinyIOC构造函数注入
- 18. 构造函数注入
- 19. MEF构造函数注入
- 20. 数据注解构造函数注入
- 21. MEF,实体框架和构造函数注入
- 22. 实体框架和构造函数注入延迟加载
- 23. 我可以在构造函数注释中引用属性注释吗?
- 24. JvmOverloads注释类主构造
- 25. 统一:构造函数注入与多个构造函数
- 26. 基于类的注释绑定构造函数参数
- 27. 通过构造函数体
- 28. 使用构造函数注入和默认构造函数是不好的?
- 29. 初始化主构造函数中的子类 - 主构造函数体与子类构造函数体
- 30. ES6类构造函数和箭头函数的解释效果