[英]zf2 annotation for select element
我對zf2注釋感到有些困惑,我根據本教程創建了一些元素:
/**
* @Annotation\Attributes({"type":"text" })
* @Annotation\Required(false)
* @Annotation\Options({"label":"Cardholder's Name: *:"})
*/
protected $cardholder;
對於簡單的文本,一切正常,但在嘗試創建選擇元素時我陷入困境。
如果您知道任何教程或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;
在視野中
<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>
嘗試這個:
/**
* @Annotation\Type("Zend\Form\Element\Select")
* @Annotation\Required(false)
* @Annotation\Options({"label":"Cardholder's Name: *:", "value_options":{"1":"VISA", "2":"MASTER CARD", "3":"AMERICAN EXPRESS"}})
*/
protected $cardholder;
嘗試這個
/**
* @Annotation\Type("Zend\Form\Element\Select")
* @Annotation\Required({"required":"false" })
* @Annotation\Filter({"name":"StringTrim"})
*
*
*/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.