且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从控制器内部获取Symfony2中Web目录的服务器路径?

更新时间:2023-11-19 18:49:52

由于框架完全独立于webdir,因此在Symfony2中实际上没有直接获取webdir路径的方法.

There's actually no direct way to get path to webdir in Symfony2 as the framework is completely independent of the webdir.

您可以在编写内核类的实例上使用getRootDir().如果以后考虑重命名/web目录,则应使其可配置.例如,AsseticBundle在其DI配置中具有这样的选项(请参见此处此处).

You can use getRootDir() on instance of kernel class, just as you write. If you consider renaming /web dir in future, you should make it configurable. For example AsseticBundle has such an option in its DI configuration (see here and here).