0

我想要实现的是使用 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>'; 
    }
}
4

0 回答 0