-- Borje <[EMAIL PROTECTED]> wrote
(on Wednesday, 16 April 2008, 12:31 PM -0700):
>
> > Matthew Weier O'Phinney-3 wrote:
> > You should create a custom decorator for that, then -- have it simply
> > emit a <td></td> -- and attach it to that button.
>
> I made a custom decorator and I'd like to use it as following:
> $this->submit->setDecorators(array(
> array(
> 'decorator' => 'ViewHelper',
> 'options' => array('helper' => 'formSubmit')),
> array(
> 'decorator' => new my_decorator(),
> 'options' => array('numColumns' => value,
> 'placement' => value)),
> array(
> 'decorator' => array('tr' => 'HtmlTag'),
> 'options' => array('tag' => 'tr')),
> ));
>
> The problem is here that I need to pass my decorator a couple of values. How
> many columns the table has and (if I ever want to use more than two) and if
> where the button should display, in the first or in the second. I can't
> modify the constructor of my decorator since that gives me a conflict with
> the Zend_Form_Decorator_Interface. And if I add options like I did in my
> example they aren't used since Zend_Form->addDecorator has this code:
>
> if ($decorator instanceof Zend_Form_Decorator_Interface) {
> $name = get_class($decorator);
> }
>
> The options aren't passed to anything.
>
> Is there any way around this?
Yes. Have your decorator extend Zend_Form_Decorator_Abstract, and
make sure that the decorator is in one of the prefix paths you set --
then you can use it just like your other decorators.
So, for instance, 'my_decorator' is a bad class name as it (a) doesn't
follow Zend coding standards, and (b) tells nothing about what it does.
>From what you say, it sounds like it's a submit button decorator -- so
let's call it 'My_Decorator_Submit'. Place it in
'My/Decorator/Submit.php' somewhere in your include_path.
Then, tell the form about the path:
$this->addElementPrefixPath('My_Decorator', 'My/Decorator/', 'decorator');
When you add the decorator, you can then add it like other decorators:
array(
'decorator' => 'Submit',
'options' => array('numColumns' => value, 'placement' => value),
)
> > Pass the 'placement' => 'append' option to the Label decorator.
> This works great, thanks.
Good.
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/