Zend表单元素使用viewHelper作为装饰器

时间:2013-07-18 11:37:23

标签: php zend-framework zend-form

我想要实现的是使用viewHelper来自定义我的元素。我知道它主要由装饰器完成,但我想知道是否可以只使用viewHelper来完成它?

我想使用viewHelper:

$defaults = $_GET;
$defaults['randomText'] = 'Something';
$defaults['something'] = 'placeholder';

$form = new Extension_Form();

$element = new Extension_Form_Element_Xhtml('randomText', $this->view->SpanAdder($defaults['randomText'])); // I'm creating Xhtml element, where I'm replacing content with viewHelper return. Want to get rid of $this->view->SpanAdder part :) 
$element->setLabel('Label');
$form->addElement($element);
unset($defaults['randomText']); // I want to get rid of this line, but unfortunately I have to have it, otherwise SpanAdder result will be overwritten.

$form->setDefaults($defaults);

我有viewHelper,它给出了我的价值范围。

class View_Helper_SpanAdder extends Zend_View_Helper_Abstract {
    public function SpanAdder($value) {
        return '<span name="' . $value . '">' . $value . '</span>'; 
    }
}

0 个答案:

没有答案