Question

I'm using app.request for various and common usages as retrieving locale, current route, etc.

{{ path(app.request.get('_route')) }}
{{ app.request.locale }}

It works fine in Development environment, but in Production the variable is simply empty. It returns always null values, so it results on all kind of errors like:

"Unable to generate a URL for the named route "" as such route does not exist."

How can I access app.request in Production environment?

Edit

I should clarify that app.request actually "exists", but for some reason it returns always empty values instead of the expected ones. If I call a nonexistent method under app.request, for instance app.request.thisdoesnotexist I get an error:

Method "thisdoesnotexist" for object "Symfony\Component\HttpFoundation\Request" does not exist in...

But I'm not getting this error, so app.request is actually defined, but empty.

Was it helpful?

Solution 2

Finally I've found a solution. It was a deployment issue with my particular setup, but it could help others in similar situations.

To shorten: rebuild your bootstrap.php with

php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php

If for any reason you are forced to run composer updates in Production with the --no-scripts option (as I am due to shared hosting restrictions), forgetting to rebuild that file can cause this issue.

OTHER TIPS

app.request work in any environment. But you missed a ):

{{ path('"'~app.request.get('_route')~'"') }}
{{ app.request.locale }}

Or try to test :

{{ app.request.get('_route') }}
{{ app.request.locale }}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top