我可以通过我的$ app变量(Silex \ Application)调用访问Web根目录和应用程序根目录的函数吗?Silex - 如何访问我的Web根目录和应用程序根目录
假设我的项目布局是这样
/src <-- Contains bootstrap.php (register all required services), controllers.php (routes)
/vendor <-- Contains autoload.php and Silex source
/web <-- Contains index.php, Creates $app, includes app/bootstrap.php and $app->run()
而在SRC/controllers.php我可能想引用我的文档根目录或应用程序根
$app
->get('/', function() use ($app) {
// Would like to do something like
$webRoot = $app->getWebRoot();
return $app['twig']->render('home.html.twig');
})
->bind('home');
我已经找到了我可以使用在树枝模板但没有方便的方法在PHP
<link href="{{ app.request.baseUrl }}/libs/bootstrap-3.2.0-dist/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
我可以使用__DIR__,dirname()等,但是好奇如果有另一种方式
我有一个'bootstrap'脚本,用于加载一个具有所有'配置目录'作为属性和'成员'的类。这在'silex'之前运行,所以'随处可用'。您可以轻松将其添加到'silex'。它还具有'dev','test'等'runtime_environment'。 – 2014-10-16 16:14:14