2

I created symfony service as described here: Symfony2: get Doctrine in a generic PHP class

Service.yml

app.lib.helpers:
    class: AppBundle\Lib\Helpers
    arguments: [doctrine.orm.entity_manager]

Class Helpers

class Helpers
{
    protected $em;

    public function __construct($entityManager)
    {
        $this->em = $entityManager;
    }

    public function checkStatuses()
    {
        $orderId = $this->em->getRepository('AppBundle:Orders')->findAll();

    }
}

In controller action

$helper = $this->get('app.lib.helpers');
$helper->checkStatuses();

But im getting error:

Error: Call to a member function getRepository() on string

What causes that problem?

Community
  • 1
  • 1
hamzo
  • 195
  • 4
  • 14

2 Answers2

3

Your service definition not correct, try this or you can read this for more explain http://symfony.com/doc/current/service_container.html:

app.lib.helpers:
    class: AppBundle\Lib\Helpers
    arguments: [@doctrine.orm.entity_manager]
Hardy Rust
  • 1,600
  • 1
  • 10
  • 12
3

I think it should be

arguments: [ "@doctrine.orm.entity_manager" ]

in your Service.yml

Rafał Cz.
  • 735
  • 9
  • 19