class Application_Form_ImageUpload extends Zend_Form
{
protected $user_id;
function __construct($id){
$this->user_id = $id;
}
public function init()
{
$user_path = '/var/www/upload/' . $this->user_id;
...
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Upload');
$this->addElement($element, 'image');
$this->addElement($submit, 'submit');
}
}
Calling:
$email = Zend_Auth::getInstance()->getIdentity();
$user_id = $mapper->getUserId($email);
$uploadForm = new Application_Form_UserImageUpload($user_id);
After adding the constructor, the output for the form becomes blank. Why is that?
Because you’ve overridden the default ZF constructor which calls init
You can solve it by calling it in yours:
Or if you want a more generic solution,
Zend_Formdefault constructor calls itssetOptionsmethod which uses magic methods to set properties, so if you write a setter in your form class it will be called with options values. Example: