【发布时间】:2017-11-01 22:44:08
【问题描述】:
我正在使用带有 slim framework 3 的 Twig 模板引擎
我的控制器中有一个简单的功能
public function test_twig($request, $response, $args) {
return $this->view->render($response, "login.phtml");
}
当我在 locahost 中运行此代码时,它运行良好,但我在我的服务器上尝试它显示一个空页面,非常奇怪的行为页面没有动态变量它只是 HTML
我也试过这个:
$str = $this->view->fetchFromString('<p>Hi, my name is {{ name }}.</p>', [
'name' => "oussama"
]);
$response->getBody()->write($str);
return $response;
它在本地主机而不是我的服务器中工作(我的服务器中有 PHP 5.6)
执行完之后我发现编译函数不能编译一个简单的 HTML 文件!!!
/** * 编译模板源代码。 * * @return string 编译后的PHP源码 * * @throws Twig_Error_Syntax 在标记化、解析或编译过程中出现错误时 */
public function compileSource(Twig_Source $source)
{
try {
return $this->compile($this->parse($this->tokenize($source)));
} catch (Twig_Error $e) {
$e->setSourceContext($source);
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Syntax(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e);
}
}
我确实遵循了代码,直到 Twig_Lexer Class Inside the Constructor 正好在这一行:
'operator' => $this->getOperatorRegex(),
【问题讨论】:
-
您的错误日志中有什么内容?
-
我在日志中找不到任何东西,我跟着代码执行我发现slim核心中的compileSource函数正在这样做
-
@AdamA 请检查我的问题编辑
-
你使用的是什么 Twig 版本?
-
我使用的是 Twig 2.2 版