I
I
Igor Chernyshev2011-12-05 15:40:10
symfony
Igor Chernyshev, 2011-12-05 15:40:10

[ symfony 2 ] Getting container in entities

Hello.

How can I get a container from an entity in symfony 2 ? Those. In the controller, this is easy to do:

$this->container->get('Doctrine');
How can I do the same in Entity?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Chernyshev, 2011-12-05
@Vir

Make entity constructor

In this case, the entity object generated by the doctrine will not receive a container in the constructor. So right?
What problem are you trying to solve
I have multiple entities:
  • Customer
  • Agent
  • Carrier
  • Recipient
  • ...
  • Courier
All of them, in fact, are users of the system. And they have at least one common method - authorization. To do this, I wanted to create a User entity that would store the ID, login and type (model / entity) of the user. And then, using magical methods, proxy the call directly to the entities to which the users actually belong. But for this, first, they must be obtained from the database.

A
Anton, 2011-12-05
@sHinE

Make an entity constructor pass a container as a parameter?
And what problem are you trying to solve that you need a container in essence?
I had problems a couple of times where I also wanted to, but I managed to do without it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question