2013-10-04 6 views
7

में तत्व के रूप में एचटीएमएल मैं जरूरत वर्ग और आईडी कैसे जोड़ें:Zend फ्रेमवर्क 2.2.4

<label for="text_field_username">User Name</lable> 
<input type="text" id="text_field_username" name="text_field_username" class="form-control" /> 

मैं इनपुट के आईडी से जोड़ने के लिए लेबल के लिए चाहते हैं। इस तरह उपयोगकर्ता इनपुट को हाइलाइट करने के लिए लेबल पर क्लिक कर सकते हैं। चेकबॉक्स के लिए अधिक उपयोगी। इसके अलावा, कम महत्वपूर्ण, मैं इनपुट क्षेत्र में कक्षा चाहता हूं।

मैं क्या करने की कोशिश की और मेरे लिए काम करता है नहीं है:

echo $this->formRow($form->get('usr_name')); 

मैं भी आंशिक लेआउट का उपयोग करने की कोशिश की।

echo $this->formElement($element); 

इस सवाल का पोस्ट करने से पहले मैं framework.zend.com/manual/2.2/en/modules/zend.form.view.helpers.html#formlabel

यह काम करता है नहीं है इस दस्तावेज़ में आए । यह इसके लिए जोड़ता है लेकिन यह कुछ भी इंगित नहीं करता है। !?

उत्तर

9

फॉर्म के प्रतिपादन के साथ आंशिक सहायता देखें, हालांकि वे स्वयं फॉर्म तत्वों के गुणों से निपटते नहीं हैं। यह फार्म वर्ग द्वारा निपटाया जाता है और यह इस काम करना चाहिए प्रपत्र तत्वों (Ie TextElement)

आप अपने फार्म के init() विधि के भीतर किसी भी रूप तत्व पर setAttribute('class', 'class name') उपयोग कर सकते हैं

तो का संग्रह है:

$element = $this->getElement('text_field_username'); 
$element->setAttribute('class', 'class name'); 
+0

मैं बहुत यकीन है कि यह वास्तव में 'setAttrib() है हूँ' ZF2 साथ –

+1

@MatthewRapati नाम 'setAttribute()' –

+0

@GuilhemSoulas अच्छी तरह से है कि एक बेहतर नाम है! मुझे बताने के लिए धन्यवाद –

8

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

namespace Application\Form; 
use Zend\Form\Form; 
class NexForm extends Form 
{ 
public function __construct($name = null) 
{ 
    parent::__construct('Nex'); 
    $this->setAttribute('method', 'post'); 
    $this->setAttribute(
     'enctype', 
     'multipart/form- data' 
    ); 
    $this->add(array(
     'name' => 'default_widget', 

     'attributes' => array(
      'type' => 'text', 
      'id' => 'default_widget', 
      'class' => 'mtz-monthpicker-widgetcontainer', 
      'required' => 'required', 
     ), 
     'options' => array(
      'label' => 'Please choose the month of records you want to display:', 
     ), 
    )); 
} 
} 

और अपने ध्यान में रखते हुए बस फोन:

 $nex=$this->app; //app is the form object we passed from controller to view 
    echo $this->formElement($nex->get('default_widget')); 
संबंधित मुद्दे