Tuesday, December 28, 2021

[FIXED] symfony 4 : How to get "/public" from RootDir

Issue

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/';


Answered By - goto

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.