2011-03-10 5 views
1

일반적으로 요소를 만들고 레이블을 설정하려면 2 줄이 필요합니다.Zend_Form_Element 자체의 setLabel

$name = new Zend_Form_Element_Text('name'); 
$name->setLabel('name'); 

나 Zend_Form_Element_Text에게 주어진 옵션으로 어쩌면, 동시에 라벨을 설정할 수 있습니다 다른 구문이 있는가, 그래서 난 그냥 1 개 라인 끝?

$name = new Zend_Form_Element_Text('name',array('label' => 'name')); 

답변

3

당신은 할 수 있습니까? 일반적으로 저는 다음과 같이합니다 :

// Inside a form class, so $this represents the form itself 
$name = $this->addElement('text', 'name', array(
    'label'  => 'Your name', 
    'description' => 'Type your name here', 
    'filters'  => array(
     'StringTrim', 
     // other filters 
    ), 
    'validators' => array(
     'NotEmpty', 
     // other validators 
    ), 
)); 
+0

젠장, 빨리 입력하십시오 ...--) –

2

당신은이 작업을 수행 할 수 있습니다 :

$name = new Zend_Form_Element_Text('name', array('label' => 'Your name'));

을하지만 중요 정말 한 줄에 유지하고있다

관련 문제