So far I was getting the cache directory from some controller. but as I want to set it in a specific service I would like to know which dependancy injection I should do to access it from a service.
Of course I could inject the container (as I settled here below as an exemple) but I guess there is some more spécific dependancy injection that I could use.
Here my code so far in my service
class mycache
{
private $container;
public function __construct($container){
$this->container = $container;
}
public function transf($text, $code)
{
$filename = $this->container->getParameter('kernel.cache_dir') . '/MyCACHE/langue.txt';
}
}
// service configuration
service
cache_langue:
class: MySite\BlogBundle\Services\mycache
arguments: ["@service_container"]
You can inject the kernel.cache_dir
parameter as follows:
services:
cache_langue:
class: MySite\BlogBundle\Services\mycache
arguments: ["%kernel.cache_dir%"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With