# Any tutorial on annotation usage with doctrine

**URL:** <https://discourse.laminas.dev/t/any-tutorial-on-annotation-usage-with-doctrine/2110>\
**Category:** Components & MVC\
**Tags:** laminas-form, laminas-mvc, doctrine\
**Created:** [February 16, 2021, 5:12am UTC](https://discourse.laminas.dev/t/any-tutorial-on-annotation-usage-with-doctrine/2110 "2021-02-16T05:12:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [February 16, 2021, 5:12am UTC](https://discourse.laminas.dev/t/any-tutorial-on-annotation-usage-with-doctrine/2110/1 "2021-02-16T05:12:17Z")

</div>

Hi,  
Is there any tutorial anyone follows on the doctrine with annotation or is there any command-line tool available which can generate annotation form based on the provided entity? Thanks!

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [February 16, 2021, 9:39am UTC](https://discourse.laminas.dev/t/any-tutorial-on-annotation-usage-with-doctrine/2110/2 "2021-02-16T09:39:17Z")

</div>

You can follow the [description in the documentation](https://docs.laminas.dev/laminas-form/quick-start/#using-annotations) and then use the builder in a factory, for example.

Based on the [description for application integration](https://docs.laminas.dev/laminas-form/application-integration/usage-in-a-laminas-mvc-application/) this means:

```php
namespace Album\Controller;

use Album\Form\AlbumForm;
use Laminas\Form\Annotation\AnnotationBuilder;
use Psr\Container\ContainerInterface;

class AlbumControllerFactory
{
    public function __invoke(ContainerInterface $container) : AlbumController
    {
        /** @var AnnotationBuilder $builder */
        $builder = $container->get(AnnotationBuilder::class);
        $form = $builder->createForm(AlbumForm::class);

        return new AlbumController($form);
    }
}

```

So far there are no CLI commands, but the [issue tracker](https://github.com/laminas/laminas-form/issues) is open for ideas. 😃

---

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [February 18, 2021, 3:22pm UTC](https://discourse.laminas.dev/t/any-tutorial-on-annotation-usage-with-doctrine/2110/3 "2021-02-18T15:22:57Z")

</div>

Thanks, @froschdesign. But I wanted a tutorial which helps integration of doctrine and it’s associations. The above-mentioned will is just setting up a factory. Which now I’m fairly aware of. Will Symfony form example will work in Laminas as is? Thanks!

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [February 18, 2021, 5:14pm UTC](https://discourse.laminas.dev/t/any-tutorial-on-annotation-usage-with-doctrine/2110/4 "2021-02-18T17:14:31Z")

</div>

I’m sorry, I do not understand what you want. In your first post you ask for form creation via annotations on entities. This can be done with the annotations of laminas-form like in the example in the documentation:

```php
use Laminas\Form\Annotation;

/**
 * @Annotation\Name("user")
 * @Annotation\Hydrator("Laminas\Hydrator\ObjectProperty")
 */
class User
{
    /**
     * @Annotation\Exclude()
     */
    public $id;

    /**
     * @Annotation\Filter({"name":"StringTrim"})
     * @Annotation\Validator({"name":"StringLength", "options":{"min":1, "max":25}})
     * @Annotation\Validator({"name":"Regex",
"options":{"pattern":"/^[a-zA-Z][a-zA-Z0-9_-]{0,24}$/"}})
     * @Annotation\Attributes({"type":"text"})
     * @Annotation\Options({"label":"Username:"})
     */
    public $username;

    /**
     * @Annotation\Type("Laminas\Form\Element\Email")
     * @Annotation\Options({"label":"Your email address:"})
     */
    public $email;
}

```

Unfortunately, I don’t know what Symfony Forms is doing on this subject.

Maybe you can enlighten us a little. 😉

---

<div class="post-metadata">

**Author:** ![ALTAMASH80](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/altamash80/32/895_2.png) [@ALTAMASH80](https://discourse.laminas.dev/u/ALTAMASH80)\
**Post date:** [February 18, 2021, 5:20pm UTC](https://discourse.laminas.dev/t/any-tutorial-on-annotation-usage-with-doctrine/2110/5 "2021-02-18T17:20:08Z")

</div>

Thanks, @froschdesign again. The example provided on the documentation is fairly simple and an advance version can be looked into with your help in laminas form. I thought maybe an example like collection integration with annotation would be there. But I’ll go through the code and see what I can find and share some examples here. Thanks again!

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [February 18, 2021, 6:45pm UTC](https://discourse.laminas.dev/t/any-tutorial-on-annotation-usage-with-doctrine/2110/6 "2021-02-18T18:45:02Z")

</div>

> [@ALTAMASH80](#):
>
> I thought maybe an example like collection integration with annotation would be there.

This information is missed in your original post. 😉

Please check the annotation `ComposedObject` for that.
