如何在Symfony 3中解决Twig_Error_Runtime

问题描述 投票:1回答:1

我继承了一个相当复杂的Symfony 3项目(我现在主要使用Laravel - 自从我使用Symfony以来已经有好几年了)所以这有点超出了我的驾驶室。

我做了一个作曲家更新,它构建好了。

composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating twig/twig 1.x-dev (e8555dc => 1445246):  Checking out 1445246d8e
Writing lock file
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

 // Clearing the cache for the dev environment with debug
 // true


 [OK] Cache for the "dev" environment (debug=true) was successfully cleared.


> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets

 Trying to install assets as relative symbolic links.

 -- -------- ----------------
     Bundle   Method / Error
 -- -------- ----------------


 [OK] All assets were successfully installed.


> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget

我清除了缓存

php bin/console cache:clear --no-warmup --env local

当我浏览到我的本地开发URL时,我得到:

Whoops, looks like something went wrong.

(4/4) Twig_Error_Runtime
An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0").

in exception_full.html.twig (line 1)
at Twig_Template->displayWithErrorHandling(array('status_code' => 500, 'status_text' => 'Internal Server Error', 'exception' => object(FlattenException), 'logger' => object(Logger), 'currentContent' => '', 'app' => object(AppVariable)), array('head' => array(object(__TwigTemplate_ed2c7b0206a4a8ba0c01ceb7e7a7f0ba342d3cbf55c912fe1f34e6abd35411c0), 'block_head'), 'title' => array(object(__TwigTemplate_ed2c7b0206a4a8ba0c01ceb7e7a7f0ba342d3cbf55c912fe1f34e6abd35411c0), 'block_title'), 'body' => array(object(__TwigTemplate_ed2c7b0206a4a8ba0c01ceb7e7a7f0ba342d3cbf55c912fe1f34e6abd35411c0), 'block_body')))
in Template.php (line 403)

<snip/>

(3/4) ContextErrorException
Notice: Undefined offset: 0

in Profiler.php (line 23)
at Twig_Extension_Profiler->enter(object(Twig_Profiler_Profile))
in ProfilerExtension.php (line 40)

<snip/>

(2/4) Twig_Error_Runtime
An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0").

in base.html.twig (line 11)
at Twig_Template->displayBlock('javascripts', array('env' => 'local', 'app' => object(AppVariable)), array('title' => array(object(__TwigTemplate_e199b3b21ccad34239564ea288dce2bfa2f11212622c2c75863848c603e82b70), 'block_title'), 'stylesheets' => array(object(__TwigTemplate_e199b3b21ccad34239564ea288dce2bfa2f11212622c2c75863848c603e82b70), 'block_stylesheets'), 'body' => array(object(__TwigTemplate_888836406c51f4232014f646f747310c541800b61ef418c11fbfcee42a1afe9b), 'block_body'), 'javascripts' => array(object(__TwigTemplate_e199b3b21ccad34239564ea288dce2bfa2f11212622c2c75863848c603e82b70), 'block_javascripts')))
in Environment.php(467) : eval()'d code (line 51)

<snip/>

(1/4) ContextErrorException
Notice: Undefined offset: 0

in Profiler.php (line 23)
at Twig_Extension_Profiler->enter(object(Twig_Profiler_Profile))
in ProfilerExtension.php (line 40)

由于这似乎是供应商文件的问题,我不知道从哪里开始。

日志中的最后一个错误是

[2018-03-02 15:56:53] request.CRITICAL: Exception thrown when handling an exception (Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0"). at /Projects/myproject/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig line 1) {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"Notice: Undefined offset: 0\"). at /Projects/myproject/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig:1, Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): Notice: Undefined offset: 0 at /Projects/myproject/vendor/twig/twig/lib/Twig/Extension/Profiler.php:23)"} []
symfony twig profiler symfony-3.3 php-7.1
1个回答
2
投票

尝试在composer.json“twig / twig”中添加这一行:“2.4.4”

对我来说工作。似乎twig 2.4.5的最后更新有这个问题。

我在这里找到了答案:https://github.com/twigphp/Twig/issues/2627

© www.soinside.com 2019 - 2024. All rights reserved.