What is right way when using Zend_Form to create concrete application forms
1) Using "extends" and derived class
class MyForm extends Zend_Form {
public function __construct() {
$el = $this->createElement('text', 'el');
$this->addElement($el);
// ...
}
}
2) Or using delegation/proxy pattern
class MyForm {
private $_form;
public function __construct() {
$this->_form = new Zend_Form();
$el = $this->createElement('text', 'el');
$this->_form->addElement($el);
// ...
}
public function __call($I_method, $I_params) {
// ... forwarding calls to private delegate
}
}
I create Form classes as per this example and use a helper to instantiate them. The inspiration came from Matthew Weier O'Phinney, ZF project lead, so I'm happy to accept it as good practice.
I'm using
My_Form extends Zend_Form
and then
My_Form_ConcreteImplementation extends My_Form
The My_Form class is used to set default decorators and stuff and the concrete impelemntation adds elements and handles the business if necessary. It makes it DRY and that's what you need. No need to keep up to academic principles :P