title: Building the elements of a Zend_Form from an Doctrine entity
body: <p>After much reading, I realized that Zend_Form can be divided into various representations, it fits well in view as the model.</p>
  
  <p>Following the logic proposed by <a href="http://weierophinney.net/matthew/archives/200-Using-Zend_Form-in-Your-Models.html" rel="nofollow noreferrer">Matthew Weier O'Phinney</a>, I got an idea to pass Doctrine [2] Entitie to the constructor of a class that extends Zend_Form, in the case, App_Form.</p>
  
  <p>So in my entitie, I have a method for each form, following the pattern:</p>
  
  <pre><code>protected function _formFormName{}()
  </code></pre>
  
  <p>that Entitie extends the abstract class App_Form_Entitie, that have a method to retrieve the form:</p>
  
  <pre><code>final public function getForm($form = null)
  </code></pre>
  
  <p>and still have the methods <em>isValid()</em> and <em>getMessage()</em>.</p>
  
  <p>But many people prefer to leave the forms in separate files, see:</p>
  
  <p><a href="https://stackoverflow.com/questions/3627531/zend-framework-where-to-place-zend-forms-controller-model-somewhere-else">Where to place Zend_Forms, Controller? Model? Somewhere else?</a></p>
  
  <p>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.</p>
  
  <p>Any answer is welcome.</p>
  
  <p>Here are two codes showing how the two examples would be, first, my proposal:</p>
  
  <pre><code>&lt;?php
  //My controller action
  /* @var $em Doctrine\ORM\EntityManager */
  $user = $em-&gt;find('MyNamespace\User', 1);
  $loginForm = new App_Form($user, array('form'=&gt; 'login'));
  $this-&gt;view-&gt;loginForm = $loginForm;
  
  //My view script
  echo $this-&gt;loginForm;
  </code></pre>
  
  <p>And here the proposal of Matthew, in which the forms are in separate files:</p>
  
  <pre><code>&lt;?php
  //My controller action
  /* @var $em Doctrine\ORM\EntityManager */
  $user = $em-&gt;find('MyNamespace\User', 1);
  $formLogin = $user-&gt;getForm('login'); //The entity creates a new instance of the class App_Form_Login and returns it.
  $this-&gt;view-&gt;formLogin = $formLogin
  
  //In my view...
  echo $this-&gt;formLogin;
  </code></pre>