In the src/Utils directory, I created a custom class Foo for various things. I\'m looking for a way to get the absolute root path of the symfony 4 project <
This is work :
// from Foo class
use Symfony\Component\HttpKernel\KernelInterface;
...
class Foo{
private $rootDir;
public function __construct(KernelInterface $kernel)
{
$this->rootDir = $kernel->getProjectDir();
}
public function myfoomethod(){
return $this->getRootDir();
}
public function getRootDir(){
return $this->rootDir;
}
}
// from the controller class
use App\Utils\Foo;
...
class FaaController extends AbstractController
{
/**
* @Route("/scenario", name="scenario")
*/
public function new(Foo $foo)
{
dump($foo->myfoomethod()); //show the dir path !
return $this->render('faa/index.html.twig');
}
}