Im trying to call a method within a service that calls ANOTHER method from another service.
Current class -> different class/service -> to different class/service
I can successfully call the initial service, but when that service tries calling an additional service i get the error
Fatal error</b>: Call to a member function get() on a non-object
Heres the code that causes the error:
$edmt = $this->get('endorsements');
And the declaration of the service:
endorsements:
class: EndorseMe\EndorsementBundle\Controller\DefaultController
arguments: [ @router, @service_container]
However, to make things trickier, this service isnt always used as a service. Its also regular symfony controller. It needs to be able to work both ways
You should be passing your second service to your first service as a parameter:
Then in your first service:
After that you should be able to use the injected service by calling
$this->injectedServiceTake a look at the Referencing Services chapter in the documentation.
EDIT: I don’t think it’s possible to use the same class both as Service and Controller. I suggest to define Controller as Service instead. In the end you would have your second service injected in your first service, and your first service injected in your controller service (three services total).