-- Hauke Stange <[email protected]> wrote
(on Wednesday, 24 August 2011, 06:38 PM +0200):
> I just spent hours with searching why my decorator doesn't get called. I
> use the Zend_Form stuff separately for testing purposes and wrote an own
> decorator for some elements.
> 
> In my form class I use the following lines of code to register and use
> my decorator:
> 
> $this->addElementPrefixPath(
>     '',
>     $this->_decoratorPath,
>     'decorator'
> );

<snip>

> After those lines 'ViewHelper' becomes to
> 'Zend_Form_Decorator_ViewHelper'. 'Description' becomes to
> 'Zend_Form_Decorator_Description'. And 'TableRowDecorator' gets unset.
> 
> By renaming TableRowDecorator to XXX_TableRowDecorator and specifying
> 
> $this->addElementPrefixPath(
>     'XXX_',
>     $this->_decoratorPath,
>     'decorator'
> );
> 
> ...all is fine.
> 
> Now my question: Is this an outstandig case of misuse and
> misunderstanding or just a bug?
> 
> A compromise maybe could be that addElementPrefixPath() just throws an
> exception or something if an empty prefix is given.

The answer lies with in Zend_Loader_PluginLoader. When it receives a
prefix to register, it normalizes it by ensuring a trailing '_' exists
on the prefix. So, internally, when you call load(), when it hits your
prefix, it's prepending "_" to the requsted plugin name. This will raise
some interesting problems -- "_" gets translated to a directory
separator when loading, which means you're going to get some odd paths
for it to test against.

So, long story short: the best practice is to always use a non-empty
prefix.

Do please file an improvement request against the component, though, so
we can raise an exception on empty prefixes.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to