2014-09-26 4 views
8

मैं ज़ेंड फ्रेमवर्क 2 फॉर्म में चयन के विकल्प में कस्टम HTML विशेषता जोड़ना चाहता हूं। अबZF2 एक चुनिंदा फॉर्म तत्व में विकल्प में कस्टम विशेषता जोड़ें

$form = new \Vente\Form\Vente; 
foreach($this->getAdminLieuDeVenteTable()->fetchAll() as $lieu) { 
     $optionsLieu[$lieu->getId()] = $lieu->getNom(); 
    } 
    $form->get('lieuRemplissage')->setValueOptions($optionsLieu); 

लेकिन, प्रत्येक विकल्प के लिए मैं चाहता हूँ:

$this->add(array(
     'name' => 'lieuRemplissage', 
     'type' => 'Select', 
     'attributes' => array(
      'class'  => 'form-control', 
     ), 
     'options' => array(
      'label' => _('Lieu pré-enregistré'), 
     ), 
    )); 

मैं इस तरह मेरी नियंत्रक में मेरे विकल्प मान:

यह मेरा फार्म वर्ग से मेरी (आंशिक) कोड है सभी चयन विकल्पों में एक HTML विशेषता जोड़ें लेकिन प्रत्येक के लिए एक अलग मूल्य के साथ।

क्या ZF2 में कोई तरीका प्राप्त करने का कोई तरीका है?

धन्यवाद।

+0

हाँ वहाँ आप valueOptions – matwr

उत्तर

5

मैं सिर्फ यह पता लगा और यहां साझा करने के लिए के बाद से मैं इस सवाल को देखा है, जबकि मैं एक ही सवाल लिए खोज रहा था चाहता था: के रूप में निम्नलिखित हैं उदाहरण के लिए डेटा- * ठीक है। सुझाए गए तरीके से एक ही परिणाम देना चाहिए लेकिन सीधे फॉर्म वर्ग में विकल्पों के गुणों का उपयोग करना चाहिए; विशेष रूप से उपयोगी अगर मेरे जैसे विकल्पों को पॉप्युलेट करने के लिए निर्माण करने के लिए डेटा ऑब्जेक्ट पास करना।

$this->add(array(
    'name' => 'lieuRemplissage', 
    'type' => 'Select', 
    'attributes' => array(
     'class'  => 'form-control', 
    ), 
    'options' => array(
     'label' => _('Lieu pré-enregistré'), 
     'value' => 123 
     'attributes' => array(
      'data-key' => 'value_for_data_attribute_goes_here', 
     ), 
    ), 
)); 
10

हाँ इस ZF2

आप विकल्प मान के अंतर्गत विशेषताएं में पारित साथ संभव है। मान सरणी प्रारूप में होना चाहिए:

// ध्यान में रखते हुए उदाहरण:

$select=new \Zend\Form\Element\Select('test'); 
$select->setValueOptions(

    [ 

     ['attributes'=>['data-key'=>'value'],'value'=>'myValue','label'=>'myLabel'] 


    ] 

    ); 

echo $this->formselect($select); 

प्रिंट:

<select name="test"><option value="myValue" data-key="value">myLabel</option></select> 

संपादित करें:

गुण प्रदान करते हैं मान्य HTML आप विशेषताओं का होना चाहिए कोई यादृच्छिक कुंजी/मूल्य जोड़े नहीं डाल सकते हैं।

protected $validGlobalAttributes = array(
     'accesskey'   => true, 
     'class'    => true, 
     'contenteditable' => true, 
     'contextmenu'  => true, 
     'dir'    => true, 
     'draggable'   => true, 
     'dropzone'   => true, 
     'hidden'    => true, 
     'id'     => true, 
     'lang'    => true, 
     'onabort'   => true, 
     'onblur'    => true, 
     'oncanplay'   => true, 
     'oncanplaythrough' => true, 
     'onchange'   => true, 
     'onclick'   => true, 
     'oncontextmenu'  => true, 
     'ondblclick'   => true, 
     'ondrag'    => true, 
     'ondragend'   => true, 
     'ondragenter'  => true, 
     'ondragleave'  => true, 
     'ondragover'   => true, 
     'ondragstart'  => true, 
     'ondrop'    => true, 
     'ondurationchange' => true, 
     'onemptied'   => true, 
     'onended'   => true, 
     'onerror'   => true, 
     'onfocus'   => true, 
     'oninput'   => true, 
     'oninvalid'   => true, 
     'onkeydown'   => true, 
     'onkeypress'   => true, 
     'onkeyup'   => true, 
     'onload'    => true, 
     'onloadeddata'  => true, 
     'onloadedmetadata' => true, 
     'onloadstart'  => true, 
     'onmousedown'  => true, 
     'onmousemove'  => true, 
     'onmouseout'   => true, 
     'onmouseover'  => true, 
     'onmouseup'   => true, 
     'onmousewheel'  => true, 
     'onpause'   => true, 
     'onplay'    => true, 
     'onplaying'   => true, 
     'onprogress'   => true, 
     'onratechange'  => true, 
     'onreadystatechange' => true, 
     'onreset'   => true, 
     'onscroll'   => true, 
     'onseeked'   => true, 
     'onseeking'   => true, 
     'onselect'   => true, 
     'onshow'    => true, 
     'onstalled'   => true, 
     'onsubmit'   => true, 
     'onsuspend'   => true, 
     'ontimeupdate'  => true, 
     'onvolumechange'  => true, 
     'onwaiting'   => true, 
     'role'    => true, 
     'aria-labelled-by' => true, 
     'aria-described-by' => true, 
     'spellcheck'   => true, 
     'style'    => true, 
     'tabindex'   => true, 
     'title'    => true, 
     'xml:base'   => true, 
     'xml:lang'   => true, 
     'xml:space'   => true, 
    ); 
+0

के अंतर्गत विशेषताएं कुंजी में कुंजी/मान पारित कर सकते हैं कर सकते हैं यह अच्छा नहीं होगा अगर इस सुविधा दर्ज किया गया है,! मैं दस्तावेज़ों को संपादित करने और पीआर बनाने के लिए प्रेरित हूं। – David

संबंधित मुद्दे