我有一個TWIG問題。此代碼在學校工作,但絕對不是我的筆記本電腦。我試圖用一個簡單的代碼,但我有錯誤:傳遞給Twig_Filter :: __ construct()的參數1必須是字符串的一個實例,字符串給出
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/2.0 SILEX /枝條2.0
感謝您的幫助。
我的代碼是非常簡單的,但是不工作:
require_once __DIR__.'/vendor/autoload.php';
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), 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();>
不能鍵入聲明標量類型在PHP5中。 https://secure.php.net/manual/en/functions.arguments.php#functions.arguments.type-claclaration –
你必須傳遞一個字符串,而不是一個字符串,這很清楚;-)(作曲家應該警告你安裝Twig 2.0與Php 5.6沒有?) –
可能重複[錯誤時將字符串傳入類型提示方法](https://stackoverflow.com/questions/3112791/error-when-passing-string-into-method-與型提示) – Axel