How to get the root dir of the Symfony2 application?

前端 未结 5 1264
耶瑟儿~
耶瑟儿~ 2021-01-29 23:36

What is the best way to get the root app directory from inside the controller? Is it possible to get it outside of the controller?

Now I get it by passing it (from param

5条回答
  •  天涯浪人
    2021-01-30 00:00

    You can also use regular expression in addition to this:

        $directoryPath = $this->container->getParameter('kernel.root_dir') . '/../web/bundles/yourbundle/';
        $directoryPath = preg_replace("/app..../i", "", $directoryPath);
        echo $directoryPath;
    

提交回复
热议问题