Pass variable to Zend form

I have a zend form instance

$form = Form_Example(); 

Now I want to pass the ID from my controller to my form.

So, I did this:

 $form = Form_Example(array('id' => $id)); 

Inside the form, I am trying to call through:

 $this->id 

But he is not there.

Does anyone know how to get this id on the form?

thanks

+4
source share
2 answers

Make sure you have a setter for the element, in your case public function setId($id) . The Zend_Form constructor checks if the setter method exists for the property, if it exists, it is called, otherwise it sets the form attribute, see setAttrib($key, $value) .

The end result will be something like this

 class Application_Form_YourForm extends Zend_Form { /** * Id * @var <type> */ protected $_id = null; /** * Setter for ID * @param <type> $id */ public function setId($id){ $this->_id = $id; } // Rest of your code... } 
+12
source

You must have access to the id property inside the form with

 $this->_attribs['id'] 
+3
source

All Articles