Details
Description
A number of users have reported that they'd like syntax like the following in Zend_Form:
<table>
<tr>
<td><?= $this->form->foo->renderLabel() ?></td>
<td>
<?= $this->form->foo->renderElement() ?>
<?= $this->form->foo->renderDescription() ?>
<?= $this->form->foo->renderErrors() ?>
</td>
</tr>
</table>
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:
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)); }
I think rendering to table (and generally speaking using tables on XHTML) is obsolete in 2008...