【发布时间】:2016-12-02 13:33:03
【问题描述】:
嘿,早上好 :)。
我将从错误消息开始,然后解释我的尝试和所做的:
Catchable fatal error: Object of class __TwigTemplate_[64chars] could not be converted to string in /someFolder/lib/Twig/Loader/Filesystem.php on line 139
完整的错误信息为图片:
调用堆栈为文本:
Call Stack
# Time Memory Function Location
1 0.0001 123400 {main}( ) ../handleOOP.php:0
2 0.0107 1269656 OOPHandler::runPage( ) ../handleOOP.php:7
3 0.0107 1269768 AnweisungEingeben->stepkontrolle( ) ../OOPHandler.php:62
4 0.0108 1271536 AnweisungEingeben->ausgabe( ) ../AnweisungEingeben.php:77
5 0.0383 1669484 Twig_Environment->render( ) ../AnweisungEingeben.php:442
6 0.0383 1669484 Twig_Environment->loadTemplate( ) ../Environment.php:347
7 0.0383 1669512 Twig_Environment->getTemplateClass( ) ../Environment.php:378
8 0.0384 1669512 Twig_Loader_Filesystem->getCacheKey( ) ../Environment.php:312
在AnweisungEingeben.php我有以下代码片段:
include_once "../lib/Twig/Autoloader.php";
Twig_Autoloader::register();
$template_dirs = array(
$root.'templates/web/anweisungen',
[...]
);
$twig_loader = new Twig_Loader_Filesystem($template_dirs);
$twig = new Twig_Environment($twig_loader, array("debug" => true));
$template = $twig->loadTemplate('Anweisung_Base.phtml');
$wech = $twig->render($template); // line 442 from AnweisungEingeben.php
我已经试过了:
- 如果路径正确(通过 scandir("path"))
- 如果 Twig 被加载
-
类似的最小代码
$loader = new Twig_Loader_Array(array('index.html' => 'Hello World!')); $twig = new Twig_Environment($loader); echo $twig->render('index.html');
不幸的是,所有的结果都是一样的。
奇怪的是,完全相同的代码在一个最小的项目中完美运行。
我知道这很混乱,但是该项目已经存在并且现在已经发展了大约 20 年,这种树枝方法是我尝试开始(!)将逻辑与 html 代码分开。
【问题讨论】:
标签: php twig template-engine