0

I'm using Silex for simple site. I use Doctrine DBAL and that project https://github.com/dflydev/dflydev-doctrine-orm-service-provider as ORM and Entity Manager. I know how access that manger from controller but I wonder how to do that from Model class. For example we have

class UserModel {

public function getPhones() {

????????

}

}

I don't know how to access EntityManager from Model class to find User Phones.

Thanks for advice

Inweo
  • 173
  • 2
  • 11

1 Answers1

0

You should not.

Instead you should set up your entities so your user has a relation to its phones, something like this:

/** @Entity */
class User
{
    /**
     * @OneToMany(targetEntity="Phone")
     */
    private $phones;
    // ...

    public function __construct() {
        $this->phones = new ArrayCollection();
    }
}

and the neccessary getters/setters. After this, you won't need the entity manager in your entity.

Maerlyn
  • 33,687
  • 18
  • 94
  • 85