-4

I would like to list all of my entity in a twig page.

I want to make a array of my entity and send the array in my twig page.

This is my entity list:

list of entity

ps: sorry for my English

BENARD Patrick
  • 30,363
  • 16
  • 99
  • 105
sky keys
  • 1
  • 1
  • 3
    Possible duplicate of [Get array/list of entities from Doctrine](https://stackoverflow.com/questions/15031534/get-array-list-of-entities-from-doctrine) – M Khalid Junaid Jun 21 '18 at 19:51
  • 2
    Stackoverflow typically deals with questions as opposed to statements. – Cerad Jun 21 '18 at 20:04
  • list containing the names of your project entities? or list of instances of a specific entity? please to be more clear, ideally with an example of the final array – Adib Aroui Jun 22 '18 at 00:12

1 Answers1

2

Usually you should post a real question or problem on StackOverflow, not only what you want...

According to the comment from @MKhalidJunaid and this link

Get array/list of entities from Doctrine

This is your solution.

AppController.php

public function entitiesAction() {
    $entities= [];
    $metas = $entityManager->getMetadataFactory()->getAllMetadata();
    foreach ($metas as $meta) {
        $entities[] = $meta->getName();
    }

    return render('entities.html.twig', [
           'entities' => $entities
    ]);
}

entities.html.twig

<ul>
    {% for entity in entities %}
        <li>{{ entity }}</li>
    {% endfor %}
</ul>
D. Schreier
  • 1,700
  • 1
  • 22
  • 34