BentCoder
BentCoder

Reputation: 12730

Accessing service container in a class

I want to be able to use $this->container in class below but how do I pass container to it with yml below? Or do I really need to pass it to access $this->container->getParameter('currency'); ? I did all the others as the example shows but failing to pass the container!

Thanks in advance

I have this code in config.yml:

services:
    data_cash:
            class:        Booking\FrontendBundle\WebService\CashManager
            arguments:    [@doctrine.orm.entity_manager, %paymentCallback%, %kernel.environment%]

This is the CashManager class:

class CashManager
{
    public function __construct($entityManager, $callback, $environment, $CONTAINER)
    {
        //$this->currency = $CONTAINER->getParameter('currency');
    }
}

Upvotes: 0

Views: 54

Answers (1)

M. Foti
M. Foti

Reputation: 3182

It is a bad idea to pass the entire container, but you have to add this in arguments: @service_container .

If you what only the parameter "currency" you have to add this: %currency%

Upvotes: 1

Related Questions