How to get the root dir of the Symfony2 application?

前端 未结 5 1304
耶瑟儿~
耶瑟儿~ 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-29 23:42

    Since Symfony 3.3 you can use binding, like

    services:
    _defaults:
        autowire: true      
        autoconfigure: true
        bind:
            $kernelProjectDir: '%kernel.project_dir%'
    

    After that you can use parameter $kernelProjectDir in any controller OR service. Just like

    class SomeControllerOrService
    {
        public function someAction(...., $kernelProjectDir)
        {
              .....
    

提交回复
热议问题