title: How to build zend 2 forms automatically from doctrine 2 entity-classes?
body: <p>Is there a way to automatically build a zend framework form by having a doctrine 2 entity-class?</p>
  
  <p>Important Information: <strong><em>This is only a example and no productive setup.</em></strong>
  E.g. </p>
  
  <p>Users (Entity) class:</p>
  
  <pre><code>use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Users
   */
  class Users
  {
      /**
       * @var string
       */
      private $name;
  
      /**
       * @var integer
       */
      private $id;
  
  
      /**
       * Set name
       *
       * @param string $name
       * @return Users
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string 
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  }
  </code></pre>
  
  <p>Users xml mapping definition:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"&gt;
    &lt;entity name="Users" table="users"&gt;
      &lt;id name="id" type="integer" column="ID"&gt;
        &lt;generator strategy="IDENTITY"/&gt;
      &lt;/id&gt;
      &lt;field name="name" type="string" column="name" length="50" nullable="true"/&gt;
    &lt;/entity&gt;
  &lt;/doctrine-mapping&gt;
  </code></pre>
  
  <p>Now i would like to have a zend 2 form class, where i can inject this entity and the form itself builds a basic form and attaches validators to this form. Here in this example it would atach a StringLenght validator (max 50; see xml mapping above) to the users field.</p>
  
  <p>Something like this is possible like i know in CakePHP. I would be really happy to have such feature in Zend framework 2, too;-)</p>
  
  <p>For now i found one link: <a href="http://www.lewanscheck.de/2013/09/21/inject-doctrine-orm-entitymanager-in-zf2-form/" rel="nofollow">http://www.lewanscheck.de/2013/09/21/inject-doctrine-orm-entitymanager-in-zf2-form/</a> but no automatic creation of validation from the xml file.</p>
  
  <p>Would be great to implement only a model/entity class with a xml/yml/annotation(even when i do not like annotations) configuration and build automatically a db schema-part (this works with doctrine 2) and a form class.  </p>