0

The situations' setup is like this:

1) I have two bundles in which I would like to use the same entity. So as suggested in this question and then in this article, I created the CommonEntitiesBundle where the desired Entity lives.

2) Then I described the model interface in both bundles I want to use the Entity in. So far so good.

Now I would like to use the interfaced Entity, just like I would use a 'bundle-native' one like this:

$clientData = new Client(); // the Entity class
$client->setName('Greg');

How should I approach it when there is only the interface available?

I used the interface in this controller.

In the Symfony's example there is only a use of the class via the ORM annotations.

Community
  • 1
  • 1
wiktus239
  • 1,404
  • 2
  • 13
  • 29

1 Answers1

0

An interface is not a class. it is instead a list of minimal necessary methods a class with 'implements [interfaceName]' must have.

Instead you could provide a example class with your bundle and use that one by default. Add configuration in app/config.yml where you can change the classname. each derived class must implement the interface for consistence.

Frank B
  • 3,667
  • 1
  • 16
  • 22
  • So do you mean that, other than for making orm dependencies' the whole `resolve_target_entities` is not needed here? And I can just put two exact same entities in two bundles, that eventually use the same one table in the db? – wiktus239 Oct 01 '15 at 21:49
  • i am still not sure what you try to reach. In each case you can use straightforward every entity in every bundle and from every other bundle. – Frank B Oct 01 '15 at 22:23
  • The goal is to use the same data, through an entity, in two different bundles. I wasn't aware you just do it straight forward. Confirm me that and I'm good to go. – wiktus239 Oct 01 '15 at 23:06