Multiple Form Element Decorators in Zend_Config

3 messages Options
Embed this post
Permalink
dvhas

Multiple Form Element Decorators in Zend_Config

Reply Threaded More More options
Print post
Permalink

I have the following in my ini configuration file.

elementdecorators.decorator = "ViewHelper"
elementdecorators.datatag.decorator = "HtmlTag"
elementdecorators.datatag.options.tag = "<td>"
elementdecorators.label.decorator = "Label"
elementdecorators.label.options.tag = "<th>"
elementdecorators.rowtag.decorator = "HtmlTag"
elementdecorators.rowtag.options.tag = "<tr>"

When I apply it to my form, it loads, but does not render correctly.

The problem is that I have two HtmlTag decorators and the '<tr>' overwrites the '<td>'.

How do you alias a decorator in a configuration file? Like on this page Using Multiple Decorators Of The Same Type

The following was my original code, it renders like I expect (and want).


$this->setElementDecorators(
  array(
  array('ViewHelper'), // prints the element
  array( array('datatag' => 'HtmlTag'), array('tag' => '<td>' )), // wrap the element in a <dt>
  array('Label', array('tag' => '<th>')), // prepend the label and wrap it in a <th>
  array('HtmlTag', array('tag' => '<tr>')) // wrap the whole thing in a <tr>
  )
);

I want to use this rendering on many custom forms.
weierophinney

Re: Multiple Form Element Decorators in Zend_Config

Reply Threaded More More options
Print post
Permalink
-- dvhas <[hidden email]> wrote
(on Monday, 07 April 2008, 12:07 PM -0700):

>
>
> I have the following in my ini configuration file.
>
> elementdecorators.decorator = "ViewHelper"
> elementdecorators.datatag.decorator = "HtmlTag"
> elementdecorators.datatag.options.tag = "<td>"
> elementdecorators.label.decorator = "Label"
> elementdecorators.label.options.tag = "<th>"
> elementdecorators.rowtag.decorator = "HtmlTag"
> elementdecorators.rowtag.options.tag = "<tr>"

First off, don't surround your tagname with brackets; those will be
escaped incorrectly if you do.

> When I apply it to my form, it loads, but does not render correctly.
>
> The problem is that I have two HtmlTag decorators and the '<tr>' overwrites
> the '<td>'.
>
> How do you alias a decorator in a configuration file? Like on this page
> http://framework.zend.com/manual/en/zend.form.forms.html Using Multiple
> Decorators Of The Same Type

Pretty easily:

    elementdecorators.datatag.type.datatag = "HtmlTag"
    elementdecorators.datatag.options.tag = "td"
    ...
    elementdecorators.rowtag.type.rowtag = "HtmlTag"
    elementdecorators.rowtag.options.tag = "tr"

This will alias the HtmlTag 'td' decorator as 'datatag', and the 'tr'
decorator as 'rowtag'.

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend - The PHP Company   | http://www.zend.com/
dvhas

Re: Multiple Form Element Decorators in Zend_Config

Reply Threaded More More options
Print post
Permalink
Works perfectly! Thanks!