After much reading, I realized that Zend_Form can be divided into various representations, it fits well in view as the model.
Following the logic proposed by Matthew Weier O'Phinney, I got an idea to pass Doctrine [2] Entitie to the constructor of a class that extends Zend_Form, in the case, App_Form.
So in my entitie, I have a method for each form, following the pattern:
protected function _formFormName{}()
that Entitie extends the abstract class App_Form_Entitie, that have a method to retrieve the form:
final public function getForm($form = null)
and still have the methods isValid() and getMessage().
But many people prefer to leave the forms in separate files, see:
Where to place Zend_Forms, Controller? Model? Somewhere else?
I wonder which of these is the best way: Pass the entity to the constructor of the form as the first parameter, and the desired form such a, optional, second parameter, or get the form from the entity (as Matthew describes) and pass as first parameter the name of the desired form.
Any answer is welcome.
Here are two codes showing how the two examples would be, first, my proposal:
<?php
//My controller action
/* @var $em Doctrine\ORM\EntityManager */
$user = $em->find('MyNamespace\User', 1);
$loginForm = new App_Form($user, array('form'=> 'login'));
$this->view->loginForm = $loginForm;
//My view script
echo $this->loginForm;
And here the proposal of Matthew, in which the forms are in separate files:
<?php
//My controller action
/* @var $em Doctrine\ORM\EntityManager */
$user = $em->find('MyNamespace\User', 1);
$formLogin = $user->getForm('login'); //The entity creates a new instance of the class App_Form_Login and returns it.
$this->view->formLogin = $formLogin
//In my view...
echo $this->formLogin;