ServiceNotFoundException Symfony 3.3

user3440145 Source

In a Symfony 3.3 Project I defined a class at

../AppBundle/Helper/ProgramHelper

like this

class ProgramHelper implements ContainerAwareInterface
{
    use ContainerAwareTrait;
    protected $em;
    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }
}

In services.yml I added it like this

services:
    ...
    app.helper.program_helper:
        class: AppBundle\Helper\ProgramHelper
        tags:
             - { name: app.helper, alias: 'container_aware' }
        arguments: [ "@doctrine.orm.entity_manager" ]
        calls:
            - [setContainer, ['@service_container']]

Now - trying to access the class from a controller like

$ph = $this->get('app.helper.program_helper');

results in this error

ServiceNotFoundException
You have requested a non-existent service "app.helper.program_helper".

Any hint on the issue is much appreciated.

phpsymfonysymfony-3.3symfony3.x

Answers

answered 6 months ago user3440145 #1

@Cerad answered the question - thank you!

Add public: true to the service definition. Services are now private by default which means that you can no longer access them via get. bin/console debug:container will confirm the service is available.

comments powered by Disqus