我試圖渲染出沒有佈局,只有幾個變量和一些循環的小枝模板。渲染小枝模板返回「緩存已損壞」並輸出PHP代碼
當我呼籲嫩枝的render()
功能,它輸出的PHP代碼塊下面的類:
php
/** path/to/my/template.html.twig */
class __TwigTemplate_435244378aba3a3f94258b7d2af4d53eb7a41acb741dd3ad0efcac038b621c67 extends Twig_Template
{
// bunch of methods for Twig_Template,
// including the compiled version of my template
}
在此之後它給我下面的異常堆棧跟蹤:
未能加載Twig模板「path/to/my/template.html.twig」,索引「」:緩存在「path/to/my/template.html.twig」中損壞。
我甚至沒有使用此應用程序緩存目前,雖然增加一個緩存似乎沒有做出不同。我使用的樹枝像這樣:
// Factory to return a new Twig environment
$loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../views/');
return new \Twig_Environment($loader);
// My class has $this->twig set to the above object
$this->twig->render('path/to/my/template.html.twig', [
'report' => $report,
'file' => $file
]);
枝條似乎能在我的模板閱讀,作爲PHP代碼在錯誤輸出塊具有模板的正確編譯版本。試圖設置可寫的緩存目錄仍然會導致相同的錯誤。
我在Apache下使用Twig 1.34.4和PHP 5.6.29。
編輯
成功的一點,在某種程度上。似乎Twig永遠不會評估它生成的代碼。
我編輯的供應商/樹枝/樹枝/ lib中/嫩枝/ Environment.php文件和行448增加了以下內容:
eval("?><?" . $content);
,我的模板處理就好了。這使我得出了Twig的其他結論正在打破的結論,但這不是一個長期的解決方案,因爲我不應該編輯供應商文件。
從456行開始的塊似乎表明$content
應該有開頭<?
但我的沒有。所以這可能會導致編譯錯誤。
更多挖掘的時間。