2010-02-20 6 views
5

Select 폼 요소를 채우는 중이고 값에서 HTML 엔터티를 사용하려고하면 특수 문자를 표시하는 대신 변환됩니다.Zend Form에서 HTML 엔터티 사용 Select

이 코드 :

<option value="one">&amp;nbsp;&amp;bull; label</option> 

하지만 난이 원하는 :

$form->field_name->addMultiOption('value', '&nbsp;&bull; label'); 

는 렌더링

<option value="one">&nbsp;&bull; label</option> 

가 어떻게 여기에 HTML 엔티티를 사용합니까?


힌트?

나는 코드에서 파고는 라벨 값에 젠드보기 추상에서 escape() 기능을 사용하는 것으로 나타났습니다. 어쩌면 누군가가 특정 양식 요소에 대해이 함수를 재정의하거나 오버로드하는 방법을 알고있을 것입니다. 기본적으로 해당 동작을 재정의하고 싶지 않습니다. 당신은 당신이 그들을 채울 때 특정 필드에 대한/명확한 젠드 필터를 전환하려고 할 수

private $_escape = 'htmlspecialchars'; 

/* SNIP */ 

public function escape($var) 
{ 
    if (in_array($this->_escape, array('htmlspecialchars', 'htmlentities'))) { 
     return call_user_func($this->_escape, $var, ENT_COMPAT, $this->_encoding); 
    } 

    return call_user_func($this->_escape, $var); 
} 
+0

당신이 당신의 예상 출력 할 어떻게할까요? –

+0

@Anthony - 원하는 출력물을 처리하기 위해 질문을 업데이트했습니다. – Sonny

답변

10

이것은 내가 만든 것처럼 복잡하지는 않습니다. 이에

$form->field_name->addMultiOption('value', '&nbsp;&bull; label'); 

:

내가이 변경

$form->field_name->addMultiOption('value', 
    html_entity_decode('&nbsp;&bull;', ENT_COMPAT, 'UTF-8') . ' label'); 
+0

폼 요소 라벨에서도이 기능을 사용할 수 있습니다! – Sonny

1

다음 Zend_View_Helper_FormSelect 클래스

protected function _build($value, $label, $selected, $disable) 
{ 
    if (is_bool($disable)) { 
     $disable = array(); 
    } 

    $opt = '<option' 
     . ' value="' . $this->view->escape($value) . '"' 
     . ' label="' . $this->view->escape($label) . '"'; 

    // selected? 
    if (in_array((string) $value, $selected)) { 
     $opt .= ' selected="selected"'; 
    } 

    // disabled? 
    if (in_array($value, $disable)) { 
     $opt .= ' disabled="disabled"'; 
    } 

    $opt .= '>' . $this->view->escape($label) . "</option>"; 

    return $opt; 
} 

이에서

기능은 Zend_View_Abstract 클래스의 함수입니다.

$form->getElement('yourElementName')->clearFilters(); 
// pupulate the element 

젠드 필터를 지울 때 먼저 채우기를 적용 할 수 있습니다.

+0

지금 시도했지만 작동하지 않았습니다. 명확하게'clearFilters()'와 필터는 일반적으로 레이블에만 적용되는 것이 아니라 값에 적용됩니다. – Sonny