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?
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.
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.