Ruben Lech
Ruben Lech

Reputation: 125

Symfony2 services

I am having hard time with my Symfony2 project. In one boundle I created two services : MainService and CurlService. I am going to use one function from CurlService in MainService. How I can do that?

    CronData:
    class: Page\MainBundle\Service\CurlService
    calls:        
        - [setEntityManager, ["@doctrine.orm.entity_manager"]]   
mainData:
    class: Page\MainBundle\Service\MainService
    calls:        
        - [setEntityManager, ["@doctrine.orm.entity_manager"], [@CronData]]

i tried this code but I don't know how refer to that function in MainService file.

Upvotes: 0

Views: 59

Answers (1)

Thomas Landauer
Thomas Landauer

Reputation: 8355

You need to inject the CurlService into MainService in your services.yml.

If you don't know how, post the important part of your services.yml (i.e. where MainService is defined).

EDIT: See here for how to call the injected service: http://symfony.com/doc/current/book/service_container.html#referencing-injecting-services

EDIT after seeing your services.yml: I guess you need to use the keyword arguments instead of calls. Then receive the "argument" (i.e. CurlService) in the constructor of MainService and assign it to $this->curlService.

Upvotes: 1

Related Questions