You can use the existing DIC to handle this:

  // DefaultController.php
  $this->get('doctrine.org.entity_manager')
       ->getRepsository('MyBundle:User')
       ->findByName('Cedric');

  // or turn it into a private method in the controller
  protected function getRepository($name)
  {
     return $this->get(...)->getRepository('MyBundle:' . $name);
  }


If you want to have a specific repository referenced in the DIC ($this-
>get('my.user_repository')), that's a little bit more work :)

-Eric

On Apr 12, 10:02 am, Skwi <cedric.spalvi...@gmail.com> wrote:
> Hi,
>
> I would like to know if there is a way to use an EntityRepository in
> the service container.
>
> I have generated several Entities with doctrine (from a YAML mapping)
> and I also have generated the associate Repositories so they extends
> the EntityRepository class.
>
> I would like to use this repositories from my code (mostly from
> Controllers) using Dependancy Injection so I tried to add these
> repositories to the service container (in my service.yml file).
> But the EntityRepository constructor requires 2 arguments : the
> EntityManager, and a ClassMetadata, and I can't find a way to provide
> them using the service.yml file.
>
> Am I totally in the wrong way ? or is there just some small things I
> missed ?
>
> Thanks in advance for your help.

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to