Symfony 2.0 getting service inside entity

前端 未结 2 1229
难免孤独
难免孤独 2020-12-02 13:08

Im seraching over and cannot find answer. I have database role model in my application. User can have a role but this role must be stored into database.

But then us

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 14:09

    You don't. This is a very common question. Entities should only know about other entities and not about the entity manager or other high level services. It can be a bit of a challenge to make the transition to this way of developing but it's usually worth it.

    What you want to do is to load the role when you load the user. Typically you will end up with a UserProvider which does this sort of thing. Have you read through the sections on security? That should be your starting point:

    http://symfony.com/doc/current/book/security.html

提交回复
热议问题