2015-01-05 3 views
1

간단한 문제가 하나 있습니다. 그러나 2-3 시간 정도 인터넷 검색을 수행 한 결과 아무 것도 발견되지 않았습니다. 그래서,이 내 양식 코드입니다 :Zend_form에서 File 요소를 렌더링 할 수 없습니다.

$element = new Zend_Form_Element_File("photo"); 
    $element->setRequired() 
        ->setDestination(realpath(APPLICATION_PATH . '/../public/uploaded_photos')) 
        ->addValidator('Count', false, 1) 
        ->addValidator('Size', false, 102400) 
        ->addValidator('Extension', false, 'jpg,png,gif') -> addValidator(new Zend_Validate_NotEmpty()) 
        ->setAllowEmpty(false); 
    $this->addElement($element); 

$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'forms/_form_addFile.phtml')))); 
    $this->setElementDecorators(array('ViewHelper')); 

그러나 파일 입력 대신에 나는이 경고가 :

경고 : 없음 파일 장식을 찾을 수 없습니다 .../가정에서 파일 요소를 렌더링 할 수 없습니다를 /wroblewski/ZendFramework-1.12.3/library/Zend/Form/Element.php 라인에 2060

Somemody 어쩌면 그것을 해결하는 방법을 알고? 필자는 File 입력을 한번도 사용하지 않았기 때문에 지금 무엇을해야하는지 모릅니다. 도와주세요 :)

+0

@nandakumarv는 무엇을 시도 했습니까? –

답변

1

$this->setElementDecorators(array('ViewHelper')); 뒤에 $this->addElement($element);과 같은 형태로 데코레이터를 설정 한 후에 파일 요소를 추가 할 수 있습니까? $this->setElementDecoratorsViewHelper이 파일 요소에 설정됩니다이 경우, 기본적으로 요소에 설정되어있는 모든 장식을 제거하고 $this->setElementDecorators() 통해 설정 한 경우에만 사람을 설정하기 때문에

이입니다. 그러나 파일 요소는 요소를 렌더링하는 데 더 많은 데코레이터가 필요합니다. 따라서 장식자를 설정 한 후에 요소를 추가하면 필요한 장식자를 제거 할 수 없습니다.

또는 함수의 두 번째 매개 변수로 배열 형식에서 제외 할 요소를 지정할 수 있습니다. 확인 Zend/Form.php 라인 2832.

/** 
* Set all element decorators as specified 
* 
* @param array $decorators 
* @param array|null $elements Specific elements to decorate or exclude from decoration 
* @param bool $include Whether $elements is an inclusion or exclusion list 
* @return Zend_Form 
*/ 
public function setElementDecorators(array $decorators, array $elements = null, $include = true) 
{ 
. 
. 
관련 문제