2010-06-04 3 views
0

저는 Zend_Db_Table_Row_Abstract-> toArray() 메소드에서 생성 된 배열로 채울 간단한 콘텐트 편집 폼 (Zend_Form)을 가지고 있습니다. 그것은 아주 잘 작동합니다.Zend_Form 전체에서 하나의 폼 요소를 채우는 방법()?

목표는 이 아니며은 값으로 양식 요소 중 하나를 채 웁니다.

현재 채우기 배열에서 특정 키 => 값 쌍을 제거하여이 문제를 해결하고 있습니다. 양식 요소 자체를 생성 할 때 그렇게 할 수있는 방법이 있는지 궁금합니다.

말 ...

$foo = new Zend_Form_Element_Textarea('foo'); 
$foo->ignoreDefaultValue(true); 
$form->addElement($foo); 

어떤 생각?

답변

0

아니요. 당신이 $form->validate($data) 또는 $form->populate($data) 할 때 은 - 내부적으로는

foreach($formElements as $element) { 
    $element->setDefault($newValue); 
} 

이 유 Zend_Form

class App_Form extends Zend_Form 
{ 
    protected $_ignoreDefaults = array(); 

    public function addIgnoredDefaultsElement(Zend_Form_Element $el) 
    { 
     $this->_ignoreDefaults[$el->getName()] = true; 
    } 

    public function isInIgnoregDefaults($name) 
    { 
     return (bool)array_key_exists($name, $this->_ignoreDefaults); 
    } 

    public function setDefault($name, $value) 
    { 
     if (!$this->isInIgnoregDefaults($name)) { 
      parent::setDefault($name, $value); 
     } 
     return $this;  
    } 
} 
을 확장하여이 쉽게 achive 수 $form->_populationInProgress = true

같은 특별한 내부 플래그를 theare하지 간단하다

관련 문제