应该在屏幕底部呈现的Web探查器栏会抛出“达到'100'最大函数嵌套级别”错误,因为它会陷入无限循环,试图在生成的代码中加载相同的模板文件。 / p>
以下是导致无限循环的两行代码。
0.5359 7623912 96. __TwigTemplate_12d25e382d980637bca9380c409ddd59->__construct(???) /var/www/site/app/cache/dev/classes.php:7999
0.5359 7624296 97. Twig_Environment->loadTemplate(???, ???) /var/www/site/app/cache/dev/twig/12/d2/5e382d980637bca9380c409ddd59.php:10
我检查了源代码,看起来相同的Twig模板在其构造函数中加载自身。我在下面列出了这两个文件的源代码片段。我确定我需要包含更多内容,但我不确定要包括哪些内容。
应用程序/高速缓存的/ dev / classes.php
public function loadTemplate($name, $index = null)
{
$cls = $this->getTemplateClass($name, $index);
if (isset($this->loadedTemplates[$cls])) {
return $this->loadedTemplates[$cls];
}
if (!class_exists($cls, false)) {
if (false === $cache = $this->getCacheFilename($name)) {
eval('?>'.$this->compileSource($this->loader->getSource($name), $name));
} else {
if (!is_file($cache) || ($this->isAutoReload() && !$this->isTemplateFresh($name, filemtime($cache)))) {
$this->writeCacheFile($cache, $this->compileSource($this->loader->getSource($name), $name));
}
require_once $cache;
}
}
if (!$this->runtimeInitialized) {
$this->initRuntime();
}
return $this->loadedTemplates[$cls] = new $cls($this); // CALLS THE CONSTRUCTOR BELOW
}
应用程序/高速缓存的/ dev /枝条/ 12 / D2 / 5e382d980637bca9380c409ddd59.php
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
$this->parent = $this->env->loadTemplate("WebProfilerBundle:Profiler:layout.html.twig"); // CALLS THE loadTemplate METHOD ABOVE
$this->blocks = array(
'body' => array($this, 'block_body'),
'panel' => array($this, 'block_panel'),
);
}
答案 0 :(得分:0)
我无法发表评论,因此我将此作为解决方案发布。遗憾。
有时,服务器配置或htaccess中定义的某些重定向或重写规则会导致无限重写或重定向。我建议修改你的路线,如改变
/foo/bar/1
到
/foo/bar/1/
或者,尝试检查重定向或重写规则。如果您100%确定您的代码是正确的,我相信您会赶上一些东西。
答案 1 :(得分:0)
这是旧的,但我最近遇到了同样的问题。
我尝试清除缓存,增加了xdebug限制,并检查了我的twig文件中的循环包含,但没有一个帮助。
对我来说,解决方法是确保我在我的composer.json
文件中加载稳定版本的twig,方法是将以下代码添加到我的require部分:
"twig/twig": "@stable"