Silex v1.3 到 Silex v2:Twig_Error_Runtime
Silex v1.3 to Silex v2: Twig_Error_Runtime
我最近将一切正常的 Silex v1.3 项目迁移到了 Silex v2。我收到一个树枝错误,我不明白原因
Twig_Error_Runtime in Template.php line 590:
Neither the property "request" nor one of the methods "request()", "getrequest()"/"isrequest()" or "__call()" exist and have public access in class "Silex\Application" in "index.twig" at line 5
这是我的 index.twig 文件的前 5 行
{% extends "layout.twig" %}
{% block stylsheets %}
<link rel="stylesheet" type="text/css" href="{{ app.request.basepath }}/public/libs/odometer/themes/odometer-theme-minimal.css" />
当然在布局中,我调用
{% block stylsheets %}{% endblock %}
但我一点也不确定,问题出在 twig 文件上...
有什么需要改变的吗?
这是控制器的摘录:
$app->get('/', function () use ($app) {
return $app['twig']->render('index.twig', [
...
]);
})->bind('homepage');
感谢帮助
我发现 app.request.uri
不再适用于最近的 Twig。
但是如果你使用 global.request.uri
它工作正常。
我在 Twig 的文档中没有找到任何相关信息。
正如 seblucas 所说,global.request.uri
工作正常。但我找到了解决此问题的另一种解决方案。您可以将 app.request.uri
替换为 app.request_stack.currentrequest.basepath
。我不知道什么是最好的解决方案...
我最近将一切正常的 Silex v1.3 项目迁移到了 Silex v2。我收到一个树枝错误,我不明白原因
Twig_Error_Runtime in Template.php line 590:
Neither the property "request" nor one of the methods "request()", "getrequest()"/"isrequest()" or "__call()" exist and have public access in class "Silex\Application" in "index.twig" at line 5
这是我的 index.twig 文件的前 5 行
{% extends "layout.twig" %}
{% block stylsheets %}
<link rel="stylesheet" type="text/css" href="{{ app.request.basepath }}/public/libs/odometer/themes/odometer-theme-minimal.css" />
当然在布局中,我调用
{% block stylsheets %}{% endblock %}
但我一点也不确定,问题出在 twig 文件上... 有什么需要改变的吗?
这是控制器的摘录:
$app->get('/', function () use ($app) {
return $app['twig']->render('index.twig', [
...
]);
})->bind('homepage');
感谢帮助
我发现 app.request.uri
不再适用于最近的 Twig。
但是如果你使用 global.request.uri
它工作正常。
我在 Twig 的文档中没有找到任何相关信息。
正如 seblucas 所说,global.request.uri
工作正常。但我找到了解决此问题的另一种解决方案。您可以将 app.request.uri
替换为 app.request_stack.currentrequest.basepath
。我不知道什么是最好的解决方案...