-- pankraz <[email protected]> wrote
(on Saturday, 06 March 2010, 04:38 PM -0800):
> i am trying to assign a custom view helper:
> 
>       public $decoRadio = array(
>               array ('ViewHelper' => 'CustomViewHeper'),
>                 'Errors',
>                  array(array('data' => 'HtmlTag'), array('tag' => 'span',
> 'class' => 'name')),
>                  array(array('row' => 'HtmlTag'), array('tag' => 'li',
> 'class' => 'radiobutton')),
>         );  
>              
> 
> This doesn't work. Any ideas?

Yep -- update the $helper property of the element to be the name of the
view helper. This can be done at either instantiation or afterwards:

    $element = new Zend_Form_Element_Radio('foo', array(
        'helper' => 'CustomViewHelper',
        'decorators' => array(
            'ViewHelper',
            'Errors',
            array(array('data' => 'HtmlTag'), array('tag' => 'span', 'class' => 
'name')),
            array(array('row' => 'HtmlTag'), array('tag' => 'li', 'class' => 
'radiobutton')),
        ),
    ));


    // or:
    $form->addElement('radio', 'foo', $sameArrayAsBefore);

    // or:
    $element->helper = 'CustomViewHelper';

You can also define a custom element to do this:

    class Foo extends Zend_Form_Element
    {
        public $helper = 'CustomViewHelper';

        public function loadDefaultDecorators()
        {
            if ($this->loadDefaultDecoratorsIsDisabled()) {
                return;
            }

            $decorators = $this->getDecorators();
            if (empty($decorators)) {
                $this->addDecorators(array(
                    'ViewHelper',
                    'Errors',
                    array(array('data' => 'HtmlTag'), array('tag' => 'span', 
'class' => 'name')),
                    array(array('row' => 'HtmlTag'), array('tag' => 'li', 
'class' => 'radiobutton')),
                ));
            }
        }
    }


-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Reply via email to