2008年8月6日星期三

Re: [fw-mvc] Trying to understand Decorators

-- Gordon Ross <gr306@ucs.cam.ac.uk> wrote
(on Wednesday, 06 August 2008, 08:30 PM +0100):
> I'm trying to understand how to create custom decorators. I've read the page at http://devzone.zend.com/article/3450-decorators-with-zend_form and I'm studying the examples in it.
>
> However, I can't work out how this:
>
> $number = new Zend_Form_Element_Text('number');
> $number->setLabel('Extension Number')
>
> //Taken straight from the web page
> $number->setDecorators(array('ViewHelper', 'Errors', array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), array('Label', array('tag' => 'td'), array(array('row' => 'HtmlTag'), array('tag' => 'tr')),)));

There's a mismatched paren in there, so the 'row' decorator is being
subsumed by the Label decorator. Try this instead:

$number = new Zend_Form_Element_Text('number');
$number->setLabel('Extension Number');

//Taken straight from the web page
$number->setDecorators(array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
));

echo $number->render(new Zend_View);

The above works fine.

> turns into this HTML:
>
> <td><label for="number" class="required">Extension Number</label></td>
> <td class="element">
> <input type="text" name="number" id="number" value="48457"></td>
>
> Can someone help me please ?
>
> Thanks,
>
> GTG
>

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: