У меня возникла проблема с аннотацией zf2. Проблема в том, что: a имеют форму с аннотациями с простыми элементами, но мне нужно добавить набор полей в аннотацию формы. Поле содержит несколько текстовых элементов. До сих пор у меня нет проблем с созданием формы в контроллере с помощью метода annotationBiulder и CreateForm. Но если я хочу передать некоторые параметры в набор полей конструктора, невозможно вызвать набор полей с аннотацией. Есть ли решение для этого?form constructor and annotation bialder
0
A
ответ
0
использование для FIELDSET
- @Annotation \ ComposedObject ("пространство имен/Entity/MyEntity")
см http://devblog.x2k.co.uk/using-the-composedobject-zend-framework-2-form-annotation/
0
Я не думаю, что это решение моей проблемы , У меня есть форма, построенный с аннотацией и с пользовательской FIELDSET внутри имени 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. com.sun.istack.internal.Nullable Annotation and Guice
- 2. Scala and Annotation
- 3. Java gui and constructor
- 4. Constant and Overloaded Constructor
- 5. C++ Constructor and Destructor
- 6. Symfony form и entity constructor
- 7. C++ Copy constructor and Operator
- 8. Hijri and Gregorian DateTime constructor
- 9. __attribute __ ((constructor)) function and autorelease
- 10. Inherit and overload default constructor
- 11. Mockery and Laravel constructor injection
- 12. C++ Singleton Constructor and Destructor
- 13. Generic Inheritance and Copy Constructor
- 14. javascript: parameterize constructor and arguments
- 15. unique_ptr member, private copy constructor and move constructor
- 16. Erase PowerPoint pen drawing and annotation
- 17. Использование Spring Scheduled Annotation and Update View
- 18. Spring Annotation and Qualifier Based Scan
- 19. JPQL Query Annotation with Limit and Offset
- 20. MKMapKit draggable annotation and drawing polygons
- 21. Spring Cloud Data Flow @EnableBinding annotation breaks constructor injection
- 22. ajax form and partials
- 23. jQuery: form and ajaxcall
- 24. Symfony2 render and form
- 25. Winforms Form Constructor vs Load event
- 26. nodejs module with constructor and methods
- 27. java constructor, array and void methods
- 28. Java Constructor and Field Initialization Order
- 29. Spring and Scala - Function1 constructor-arg
- 30. C++ Copy Constructor and Assignment Operator