2016-07-20 2 views
2

최근 Silex v2에 모든 것이 잘 작동되는 Silex v1.3 프로젝트를 마이그레이션했습니다. 나는 원인Silex v1.3에서 Silex v2로 : Twig_Error_Runtime

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 %} 

하지만 확실하지 않습니다. 문제는 나뭇 가지 파일에 있습니다 ... 뭔가 변경해야합니까? 도움

답변

4

에 대한

$app->get('/', function() use ($app) { 

    return $app['twig']->render('index.twig', [ 
     ... 
    ]); 
})->bind('homepage'); 

덕분에 내가 app.request.uri 최근 나뭇 가지와 더 이상 작동하지 않는 것을 발견 : 여기

컨트롤러의 추출물이다.

그러나 global.request.uri을 사용하면 정상적으로 작동합니다.

트위 그의 설명서에서 이에 대한 정보를 찾지 못했습니다.

+0

나를 위해 트릭을했기 때문에 그냥 상향 조정했는데, 왜 내가 선택한 대답이 나에게 효과가 없었는지 모르겠다. 호기심에서 어떻게 찾았습니까? – mikelovelyuk

+0

두 답변 모두 나를 위해 일하지만, app.request를 global.request로 변경하는 것이 더 쉽다는 것에 동의합니다. – Macbernie

+0

@mikelovelyuk 코드를 읽음으로써 알게되었습니다. (한 달 전에 이것을 발견했습니다 : http : //silex.sensiolabs. org/doc/providers/twig.html # global-variable – seblucas

3

seblucas가 말한 것처럼 global.request.uri이 정상적으로 작동합니다. 하지만이 문제를 해결할 다른 해결책을 찾았습니다. app.request.uriapp.request_stack.currentrequest.basepath으로 바꿀 수 있습니다. 나는 무엇이 최선의 해결책인지 모르겠다. ...

+0

전역 변수가 내 케이스에는 없지만 app.request_stack.currentrequest.basepath가 작업을 완료했습니다. –