In Symfony 4, from a controller I can get the root path of my project via :
// From a Controller Class, in the src/Controller dir
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
// ...
Class myController extends Controller{
// ...
// in a public method
$rootDir = $this->get('kernel')->getRootDir();
But how can I get the root path from a Service Class ? I tried this (ugly) way
// From a Service Class, in the src/Service dir
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
// ...
Class myService extends Controller{
// ...
// in a public method
$rootDir = $this->get('kernel')->getRootDir();
But when I did that, I get the error :
"Call to a member function get() on null"
Why this solution does not work?