Argument 1 passed to Twig_Filter::__construct() must be an instance of string, string given(传递给 Twig_Filter::__construct() 的参数 1 必须是字符串的实例,给定的字符串)
问题描述
我对 TWIG 有疑问.此代码在学校有效,但绝对不适用于我的笔记本电脑.我尝试了一个简单的代码,但出现错误:
I have a problem with TWIG. This code works at school but absolutely not with my laptop. I tried with a simple code but I have the error:
可捕获的致命错误:传递给 Twig_Filter::__construct() 的参数 1 必须是字符串的实例,给定的字符串,在/opt/lampp/htdocs/webalizer/projetSilex/vendor/twig/twig/lib/Twig/中调用第 139 行的 Extension/Core.php 并在第 35 行的/opt/lampp/htdocs/webalizer/projetSilex/vendor/twig/twig/lib/Twig/Filter.php 中定义
Catchable fatal error: Argument 1 passed to Twig_Filter::__construct() must be an instance of string, string given, called in /opt/lampp/htdocs/webalizer/projetSilex/vendor/twig/twig/lib/Twig/Extension/Core.php on line 139 and defined in /opt/lampp/htdocs/webalizer/projetSilex/vendor/twig/twig/lib/Twig/Filter.php on line 35
我使用 php 5.6/SILEX 2.0/Twig 2.0
I use php 5.6 / SILEX 2.0 / Twig 2.0
感谢您的帮助.
我的代码很简单但是不起作用:
My code is very simple but doesn't work:
require_once __DIR__.'/vendor/autoload.php';
$app = new SilexApplication();
$app->register(new SilexProviderTwigServiceProvider(), array(
'twig.path' => __DIR__.'/views',
));
$app->get('/', function(){
return "hello";
});
$app->get('/hello/{name}', function($name)use($app){
return $app['twig']->render('hello.twig',
array("name"=>$name
));
});
$app->run();>
推荐答案
@CharlotteDunois 指出了这一点,但是 Twig 2.0 要求 >=PHP7.0,所以在你的环境(php 5.6)中你不能使用 Twig 2.0.来自 Twig 官方文档:
@CharlotteDunois pointed this out, but Twig 2.0 requires >=PHP7.0, so in your environment (php 5.6) you can't use Twig 2.0. From the Twig official documentation:
先决条件
Twig 至少需要 PHP 7.0.0 才能运行.
Twig needs at least PHP 7.0.0 to run.
请注意,对于 PHP5.x 分支,您仍然可以使用 Twig 1.x
Notice that for PHP5.x branch you still have Twig 1.x aviable
这篇关于传递给 Twig_Filter::__construct() 的参数 1 必须是字符串的实例,给定的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:传递给 Twig_Filter::__construct() 的参数 1 必须是字符串的实例,给定的字符串


基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01