Consider first what your "new Zend_Form()" call would look like if you
construct everything in one go. E.g.:
$form = new Zend_Form(array(
'elements' => array(
'foo' => array('text', array(
'label' => 'Foo',
'validators' => array(
array('StringLength', true, array(5, 10))
),
'decorators' => array(
'Label',
array(
array('labelTd' => 'HtmlTag'),
array('tag' => 'td', 'class' => 'labelWrap'),
),
array(
array('elemTdOpen' => 'HtmlTag'),
array('tag' => 'td', 'openOnly' => true,
'placement' => 'append'),
),
'ViewHelper',
'Errors',
array(
array('elemTdClose' => 'HtmlTag'),
array('tag' => 'td', 'closeOnly' => true,
'placement' => 'append'),
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'tr'),
)
)
))
),
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'table', 'class' =>
'table-form')),
'Form',
)
));
Take that huge array, then stick a key to every node that doesn't have one.
For ini configs, numeric keys would do. Feel free to use keys like "options"
or "type" where they make sense.
$opts = array(
'elements' => array(
'foo' => array(0 => 'text', 1 => array(
'label' => 'Foo',
'validators' => array(
0 => array(0 => 'StringLength', 1 => true, 2 =>
array(5, 10))
),
'decorators' => array(
0 => 'Label',
1 => array(
0 => array('labelTd' => 'HtmlTag'),
1 => array('tag' => 'td', 'class' =>
'labelWrap'),
),
2 => array(
0 => array('elemTdOpen' => 'HtmlTag'),
1 => array('tag' => 'td', 'openOnly' => true,
'placement' => 'append'),
),
3 => 'ViewHelper',
4 => 'Errors',
5 => array(
0 => array('elemTdClose' => 'HtmlTag'),
1 => array('tag' => 'td', 'closeOnly' => true,
'placement' => 'append'),
),
6 => array(
0 => array('row' => 'HtmlTag'),
1 => array('tag' => 'tr'),
)
)
))
),
'decorators' => array(
0 => 'FormElements',
1 => array(0 => 'HtmlTag', 1 => array('tag' => 'table',
'class' => 'table-form')),
2 => 'Form',
)
);
$form = new Zend_Form($opts);
Flatten by turning every key into a ".key" and the leaf nodes into values:
elements.foo.0 = text
elements.foo.1.label = Foo
elements.foo.1.validators.0.0 = StringLength
elements.foo.1.validators.0.1 = true
elements.foo.1.validators.0.2.min = 5
elements.foo.1.validators.0.2.max = 10
elements.foo.1.decorators.0 = Label
elements.foo.1.decorators.1.0.labelTd = HtmlTag
elements.foo.1.decorators.1.1.tag = td
elements.foo.1.decorators.1.1.class = labelWrap
elements.foo.1.decorators.2.0.elemTdOpen = HtmlTag
elements.foo.1.decorators.2.1.tag = td
elements.foo.1.decorators.2.1.openOnly = true
elements.foo.1.decorators.2.1.placement = append
elements.foo.1.decorators.3 = ViewHelper
elements.foo.1.decorators.4 = Errors
elements.foo.1.decorators.5.0.elemTdClose = HtmlTag
elements.foo.1.decorators.5.1.tag = td
elements.foo.1.decorators.5.1.closeOnly = true
elements.foo.1.decorators.5.1.placement = append
elements.foo.1.decorators.6.0.row = HtmlTag
elements.foo.1.decorators.6.1.tag = tr
decorators.0 = FormElements
decorators.1.0 = HtmlTag
decorators.1.1.tag = table
decorators.1.1.class = table-form
decorators.2 = Form
As you may have imagined, there'd be a hell lot of repetition in the
resulting ini. I prefer to just leave the default decorators alone and
render them invidividually (
http://mikaelkael.fr/doczf/1.10/en/learning.form.decorators.individual.html
).
-- Mon
On Fri, Jan 8, 2010 at 4:23 AM, Mike Wright <[email protected]>wrote:
> Hi all,
>
> Back again. Hope I'm not a pest here but I'm having a really hard time
> figuring out how this is done.
>
> I create a form from a config file but the created form is already
> decorated. If I try to change the decorators after that chunks of the form
> disappear, if not the whole form itself. I can't decorate a non-existent
> form before it is created so the decorators must be specified within the
> form's config.ini file. That's where I'm falling down.
>
> I've spent days on this. I've "grep"ed the manual for \.decorators\. but
> only find TOC links so there isn't a single example in there. I am totally
> lost, feel like an incompetent idiot, and desperately need help.
>
> A little insight and I might get my sea legs back :)
>
> Given this simple config.ini how do I specify the decorators? I've defined
> validators similarly, and so imagine that filters and decorators can be
> specified this way, too.
>
> [store]
> id = "store"
> options.decorators... ???
>
> elements.name.type = "text"
> elements.name.options.validators.strlen.validator = "StringLength"
> elements.name.options.validators.strlen.options.max = 25
>
> elements.name.options.decorators... ???
>
>
> Many, many thanks in advance,
> Mike Wright
>