我有一个symfony应用程序,当在生产服务器上运行时没有正确处理404错误时,这是我在错误日志中得到的错误:
Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in /var/www/site/releases/20160119210649/app/cache/prod/appProdUrlMatcher.php:7768
Stack trace:
0 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(1419): appProdUrlMatcher->match('/daf')
1 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(8339): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
2 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(2483): JMS\I18nRoutingBundle\Router\I18nRouter->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
3 [internal function]: Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
4 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(2264): call_user_func(Array, O in /var/www/site/releases/20160119210649/app/cache/prod/classes.php on line 5336
我在/app/Resources/TwigBundle/views/Exception/error404.html.twig中自定义了我的404错误 我已经清除了缓存甚至重新启动的php和nginx。
答案 0 :(得分:2)
我有完全相同的错误,经过长时间的研究后找到了解决方案。我的页脚中有一个语言切换,这些路由是使用当前路由和_locale
参数生成的。
{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'de'})) }}
但是在404错误上没有路线。这结束了这500错误。 现在我把这个链接包装成这样的if语句并且它可以工作:
<li>
<a href="{% if app.request.get('_route') != "" and app.request.get('_route_params') is not null %}
{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'en'})) }}
{% else %}
{{ path("homepage", {'_locale': 'en'}) }}
{% endif %}">
English
</a>
</li>