(on Sunday, 01 March 2009, 11:15 AM +0100):
> When creating a new instance of a zend form element how to you give it a
> name with brackets?
> The Zend_Form_Element::setName() method calls the
> Zend_Form_Element::filterName() method which taks as a second argument
> $allowBrackets boolean.
>
> So how do I set the name with brackets?
So, first off, names are not allowed to have brackets internally so that
a variety of other features will work (overloading access, primarily).
That said, you *can* force brackets to appear in the output in a couple
of different ways.
* If you want brackets for allowing multiple values to be captured --
i.e., a name like 'foo[]' -- turn on the isArray property:
$element->setIsArray(true); // or pass a true value to the
// "isArray" key during
// instantiation
* If you want the value to be a key in another value, e.g.,
"bar[foo]", then you need to tell the element it belongs to another
value:
$element->setBelongsTo('bar'); // or pass the value to the
// 'belongsTo' key during
// instantiation
* If you use sub forms, array notation happens by default; all
elements "belongTo" the name of the sub form
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论