Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:17:16+00:00 2026-06-14T17:17:16+00:00

What I want to know is the best way to create a form which

  • 0

What I want to know is the best way to create a form which matches an entity.

  • Manually Create the form either in code or using the form annotations?
  • Using Annotations from the entity?

I’ve see a few different examples, some using @Annotation and others using @Form? Could somebody please explain the difference?

In the case of entities having related/nested entities do I need to provide a custom hydrator for every entity? I’m presuming Doctrine may already have one that implements the hydrator interfaces?

To Summarise:
– Best way to create a form from an Entity.
– Difference between @Form and @Annotation
– Does Doctrine have a Hydrator for it’s Entities?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:17:17+00:00Added an answer on June 14, 2026 at 5:17 pm

    First off: Annotations are a Speed-Killer. If you want to use the annotation builder, please ALWAYS Cache the created objects. But annotations are also the easiest way to get a form running 😉

    Second: The Hydrator. When using ZF2 Forms in conjunction with Doctrine 2 you most likely want to use the DoctrineEntity Hydrator located inside. Consider the following code:

    $form = new ReferenzwertForm();
    $form->setHydrator(new DoctrineEntity($serviceLocator->get('Doctrine\ORM\EntityManager')))
         ->setObject(new Referenzwert())
         ->setInputFilter(new ReferenzwertFilter())
         ->setAttribute('method', 'post');
    return $form;
    
    • ReferenzwertForm() is of type Zend\Form\Form Object
    • DoctrineEntity() is of type DoctrineORMModule\Stdlib\Hydrator\DoctrineEntity
      • DoctrineEntity needs the EntityManager provided. You should be familiar with this when using Doctrine 2 in ZF2
    • Referenzwert() is a Entity-Object

    When not using annotations and you’re referencing another Entity, then make sure you use the appropriate form element (in most cases this would be a select-element (like selecting a CategoryEntity for a BlogEntity or something)

    $this->add(array(
        'name' => 'type',
        'type' => 'DoctrineORMModule\Form\Element\DoctrineEntity',
        'options' => array(
              'label' => 'Choose a MyEntity',
              'object_manager' => $this->getEntityManager(),
              'target_class' => 'Namespace\Entity\MyEntity',
              'property' => 'name'
        ),
        'attributes' => array(
            'required' => true
        )
    ));
    

    As you can see, the Form element needs to know about the entityManager, too. This is why ideally you’d want to extend the first Code-Example with another setter to inject the entityManager into your form object.

    $form->setEntityManager($serviceLocator->get('Doctrine\ORM\EntityManager'))
         ->set()//all the other stuff
    

    What’s the best approach in general? I’d say there is none. For speed purposes, annotations solely are a killer. Using cached versions should help out, though i have no personal experience with caching in ZF2 just yet. I like to create my forms from hand outside of annotations, simply because my IDE supports a lot of stuff, but certainly not form annotations 😀

    Hope this could help you a bit and i didn’t write too much out of context 😛

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an android app and I want to know the best way
I've been at this for a while and want to know the best way
i want to know which parsing method is best to use among Simple XML
I want to know which component is best to display multiple line of text's(
I want to know what framework/Interface/API's Set is best to use to create multi-process
I want to know the best way of testing data access functionality. I know
I want to know the best way of hosting a web application for different
I am using certain plugins and code from blogs in my app. I want
I want to know what the best way is to have two divs (unless
I want to know what the best practice is for passing values (sometimes multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.