0

I have the following settings in service.yml

  appbundle.entity.countryrepository:
    class: AppBundle\Repository\CountryRepository
    calls:
      - [setPagination, ['@knp_paginator']]

code in controller is:

$countryRepository = $em->getRepository('AppBundle:Country');

When the object is created, setPagination() is never called?

What can be the reason/faults?

Gopal Joshi
  • 2,350
  • 22
  • 49
shobekhan
  • 171
  • 1
  • 2
  • 15
  • 3
    Because $em->getRepository has no idea that the container even exists. Adjust your service definition to use a factory to create the repository (search for examples for the syntax) and then access the repository using $this->get('appbundle.entity.countryrepository'); – Cerad Nov 21 '16 at 00:19
  • You are doing it wrong. You can't define a repository as a service this way. Check this question: http://stackoverflow.com/questions/17228417/symfony-2-creating-a-service-from-a-repository – Denis V Nov 21 '16 at 06:07
  • Thank you Cerad and Denis. I used a factory to create the repository and used the controller get function as explained in your comment. – shobekhan Nov 21 '16 at 21:22

0 Answers0