我一直收到致命错误:未捕获的TypeError:传递给Slim \ Views \ Twig :: __ construct()的参数1必须是Twig \ Loader \ LoaderInterface的实例,字符串已给定...
代码是:
require DIR .'/vendor/autoload.php';
$container = new Container(); AppFactory::setContainer($container);
$app = AppFactory::create();
//$twig = new Twig('./templates',['cache'=> false]);
//$twigMiddleware = new TwigMiddleware($twig, $container, $app->getRouteCollector()
->getRouteParser(), '');
//$app->add($twigMiddleware);
//$routeParser = $app->getRouteCollector()->getRouteParser();
//$twig = new Twig(DIR.'/templates');
//$twigMiddleware = new TwigMiddleware($twig, $container,$routeParser);
//$app->add($twigMiddleware);
$container->set('view', function(){ return new Twig('./templates', ['cache'=>false]); });
$app->add(TwigMiddleware::createFromContainer($app));
我正在使用
"require": {
"slim/slim": "4.3.0",
"slim/psr7": "^0.6.0",
"php-di/php-di": "^6.0",
"slim/twig-view": "3.x-dev"
}
我尝试了其他选项(有评论)。有谁能够帮助我?我不知道这个 谢谢
答案 0 :(得分:0)
这是关于树枝上的版本,您可以解决更改代码的问题
//set view container before create app
$container->set('view', function () {
return Twig::create('views', ['cache'], false)
})
//and instead adding $twigmiddleware code this at the same line of $twigmiddleware
$app->add(Twigmiddleware::createFromContainer($app));
这将适用于新版本的树枝