最近我通过 Composer for PHP7.2 安装了 Twig2.0,运行代码时出现这些错误,
(!)致命错误:未捕获的错误:第 4 行的 C:\wamp64\www\php-twig\example.php 中找不到类 'Twig_Autoloader'
( ! ) 错误:在第 4 行的 C:\wamp64\www\php-twig\example.php 中找不到类 'Twig_Autoloader'
我浏览了 GitHub 中的问题。
这是我的PHP代码,
<?php
require 'vendor/autoload.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('templates');
$options = array(
'name' => 'Sumithran',
);
$twig = new Twig_Environment($loader, $options);
和 index.twig
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Twig test</title>
</head>
<body>
<h1>Hello world</h1>
<p>And hello {{ name }}</p>
</body>
</html>
如何解决这个问题?
提前致谢!