Mac*_*nie 3 php templates symfony twig silex
我最近将我的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
Run Code Online (Sandbox Code Playgroud)
这是我的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" />
Run Code Online (Sandbox Code Playgroud)
当然在布局中,我称之为
{% block stylsheets %}{% endblock %}
Run Code Online (Sandbox Code Playgroud)
但我完全不确定,问题出现在twig文件上......是否有必要改变?
这是控制器的摘录:
$app->get('/', function () use ($app) {
return $app['twig']->render('index.twig', [
...
]);
})->bind('homepage');
Run Code Online (Sandbox Code Playgroud)
感谢帮助
正如 seblucas 所说,global.request.uri工作正常。但是我找到了另一个解决方案来解决这个问题。您可以替换app.request.uri为app.request_stack.currentrequest.basepath. 我不知道什么是最好的解决方案...
| 归档时间: |
|
| 查看次数: |
706 次 |
| 最近记录: |