2009年9月11日星期五

Re: [fw-mvc] Array notation and ZendSubforms

-- Cristian Bichis <contact@zftutorials.com> wrote
(on Friday, 11 September 2009, 03:31 PM +0300):
> -- Cristian Bichis <contact@zftutorials.com> wrote
> (on Friday, 11 September 2009, 02:27 PM +0300):
> Anyone knows why if i set a subform name to 0, the output html into array
> notation looks like:
>
> form[]
> instead of
> form[0]
> ?
>
> This makes lot of problems sometime... I am not sure if is a bug or not...
>
>
> All subform, display group, and element names must be valid PHP variable
> names; integer names do not work.
>
> I'll be rethinking this design decision for 2.0, but for now, that's
> simply the way it works.
>
>
> Thanks!
>
> How complicated is to chnage this into a derived class or something like that ?
> Any tips how to do it to avoid this design pattern ?

It's not complicated at all -- override the filterName() method in your
forms/elements/sub forms/display groups/etc, and either allow any value
or provide a more lenient regular expression for filtering.

While that part isn't complicated, the reason we can't just make this
change at this time is because doing so breaks some of the overloading
capabilities. For instance, right now, you can grab any element, sub
form, or display group via property access:

$element = $form->foo;
$subform = $form->bar;
$group = $form->baz;

If we allow names other than valid PHP variable names, we can't offer
overloading -- and that would be a BC break.

At this point, I think it's worth doing, but it either needs to wait
until 2.0, or we need to introduce an optional flag for "allow arbitrary
names" that disables overloading.

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: