Search code examples
symfonysymfony4symfony5

symfony 4 : How to get "/public" from RootDir


I have an image under the public folder.
How can I get my image directory in symfony4 ?
In symfony 3, it's equivalent is :

$webPath = $this->get('kernel')->getRootDir() . '/../web/';

Solution

  • You can use either

    $webPath = $this->get('kernel')->getProjectDir() . '/public/'; 
    

    Or the parameter %kernel.project_dir%

    $container->getParameter('kernel.project_dir') . '/public/';