Nik*_*ich 4 zend-form zend-framework2
我对zf2注释感到有些困惑,我根据本教程创建了一些元素:
/**
* @Annotation\Attributes({"type":"text" })
* @Annotation\Required(false)
* @Annotation\Options({"label":"Cardholder's Name: *:"})
*/
protected $cardholder;
Run Code Online (Sandbox Code Playgroud)
对于简单的文本,一切正常,但在尝试创建选择元素时我陷入困境.
如果您知道任何教程或github回购,请告诉我.
问题在视图中,因此要获得选择,您需要
添加验证和过滤示例
/**
* @Annotation\Attributes({"type":"text" })
* @Annotation\Options({"label":"Cardholder's Name: *:"})
* @Annotation\Required(false)
* @Annotation\Filters({"name":"StripTags"},{"name":"StringTrim"}})
* @Annotation\Validator({"name":"StringLength","options":{"min":"1", "max":"20"}})
*/
protected $cardholder;
/**
* @Annotation\Type("Zend\Form\Element\Select")
* @Annotation\Options({"label":"Description"})
* @Annotation\Attributes({"options":{"1":"Visa","2":"Maestro"}})
*/
protected $cardType;
Run Code Online (Sandbox Code Playgroud)
在视野中
<dt><?php echo $this->formLabel($form->get('cardholder')); ?></dt>
<dd><?php
echo $this->formInput($form->get('cardholder'));
echo $this->formElementErrors($form->get('cardholder'));
?></dd>
<dt><?php echo $this->formLabel($form->get('cardType')); ?></dt>
<dd><?php
echo $this->formSelect($form->get('cardType'));
echo $this->formElementErrors($form->get('cardType'));
?></dd>
Run Code Online (Sandbox Code Playgroud)