Issues

ZF-3217: Add overloading to decorators to Zend_Form

Issue Type: Improvement Created: 2008-05-07T04:45:50.000+0000 Last Updated: 2008-09-09T12:18:44.000+0000 Status: Resolved Fix version(s): - 1.6.1 (15/Sep/08)

Reporter: Matthew Weier O'Phinney (matthew) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:

Description

A number of users have reported that they'd like syntax like the following in Zend_Form:

<pre class="highlight">


<?= $this->form->foo->renderLabel() ?>
        
            <?= $this->form->foo->renderElement() ?>
            <?= $this->form->foo->renderDescription() ?>
            <?= $this->form->foo->renderErrors() ?>
        

The idea is that they would like to selectively render specific metadata from the element or form.

This could be done fairly easily by using overloading. __call() could intercept methods beginning in 'render', and if the remainder of the method matches a decorator, would render that decorator.

As a sample implementation:

<pre class="highlight">
public function __call($method, $args)
{
    if ('render' == substr($method, 0, 6)) {
        $decoratorName = ucfirst(substr($method, 6));
        if (false !== ($decorator = $this->getDecorator($decoratorName))) {
            $seed = '';
            if (0 < count($args)) {
                $seed = array_shift($args);
            }
            return $decorator->render($seed);
        }
        require_once 'Zend/Form/Exception.php';
        throw new Zend_Form_Exception(sprintf('Decorator by name %s does not exist', $decoratorName));
    }
    require_once 'Zend/Form/Exception.php';
    throw new Zend_Form_Exception(sprintf('Method %s does not exist', $method));
}

Comments

Posted by Cristian Bichis (avantis) on 2008-05-07T05:36:08.000+0000

I think rendering to table (and generally speaking using tables on XHTML) is obsolete in 2008...

Posted by Eric Coleman (eric) on 2008-05-07T05:58:50.000+0000

Cristian... the ticket isn't about "tables" it's about the extensions to form rendering. I'd love to see this myself.

Posted by Torsten Bühl (tbuehl) on 2008-05-21T05:21:37.000+0000

Hello Matthew,

I am working at a project right now and want to change to Zend_Form from my own Form Implementation. How can I implement this feature quick in the class? I tried to copy & paste your code but it's not working. There is no Element Decorator.

Best, Torsten

Posted by Goran Juric (gog) on 2008-09-08T12:29:20.000+0000

Haven't tried it, but I think you should be able to do something like this:

Create a view helper:

[code]

<

table>

element->getLabel() ?> element->render() ?> element->getDescription() ?> element->getErrors() ?> [/code] and add it to the element (or extend Zend\_Form and set this to all elements) via a ViewScript decorator.

Posted by Matthew Weier O'Phinney (matthew) on 2008-09-08T12:56:51.000+0000

Goran -- not quite what the reporter is looking for. The idea is to be able to render an individual decorator at a time, not just the metadata.

Posted by Matthew Weier O'Phinney (matthew) on 2008-09-09T12:18:44.000+0000

Patch applied to trunk and 1.6 release branch; will release with 1.6.1

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts