symfony 4 : How to get “/public” from RootDir

后端 未结 5 1626
孤街浪徒
孤街浪徒 2021-02-05 08:13

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         


        
5条回答
  •  情歌与酒
    2021-02-05 08:22

    You can inject KernelInterface to the service or whatever and then get the project directory with $kernel->getProjectDir():

    projectDir = $kernel->getProjectDir();
        }
    
        public function showProjectDir()
        {
            echo "This is the project directory: " . $this->projectDir;
        }
    }
    

提交回复
热议问题