Wizard
Wizard

Reputation: 11265

Zend element decorator

I created an element submit:

   $this->addElement('submit', 'button', array(
        'ignore'   => true,
        'label'    => 'Update',
        'class' => 'btn blue',
    ));

And now try to set for this element decorator:

    $submit = $this->getElement('submit');
    $submit->setDecorators(array(
        array('ViewHelper'),
        array('Description'),
        array('HtmlTag', array('tag' => 'div', 'class'=>'submit-group')),
    ));

Something is wrong in my code because I get fatal error that I call member function setDecorators on no object?

Upvotes: 0

Views: 78

Answers (1)

projeqht
projeqht

Reputation: 3160

I think you either need to change:

$submit = $this->getElement('submit');

to

$submit = $this->getElement('button');

OR

$this->addElement('submit', 'button', array(
    'ignore'   => true,
    'label'    => 'Update',
    'class' => 'btn blue',
));

to

$this->addElement('submit', 'submit', array(
    'ignore'   => true,
    'label'    => 'Update',
    'class' => 'btn blue',
));

It appears the first parameter for addElement is the element type and the second parameter is the element id. Not the other way around.

And, getElement needs to take in that element id for it to work, not the element type

See here for more information: http://framework.zend.com/apidoc/1.10/_Form.html#Zend_Form::addElement() http://framework.zend.com/apidoc/1.10/_Form.html#Zend_Form::getElement()

Upvotes: 1

Related Questions