Twig未在Silex中加载

时间:2012-04-10 09:53:18

标签: twig silex

我正在尝试使用Silex FW运行应用程序。我有类似的示例源代码:

require_once __DIR__.'/silex.phar'; 

$app = new Silex\Application(); 

$app['debug'] = true;

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__ . '/views',
    'twig.class_path' => __DIR__ . '/vendor/twig/lib',
));

$app->get('/hello/{name}', function ($name) use ($app) {
    return $app['twig']->render('hello.twig', array(
        'name' => $name,
    ));
}); 

$app->run(); 

但是我收到了这个错误:

Fatal error:  Class 'Twig_Environment' not found in phar:///var/www/silex/silex.phar/src/Silex/Provider/TwigServiceProvider.php on line 40
Stack trace:
  1. {main}() /var/www/silex/index.php:0
  2. Silex\\Application->run() /var/www/silex/index.php:20
  3. Silex\\Application->handle() phar:///var/www/silex/silex.phar/src/Silex/Application.php:396
  4. Symfony\\Component\\HttpKernel\\HttpKernel->handle() phar:///var/www/silex/silex.phar/src/Silex/Application.php:411
  5. Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:72
  6. call_user_func_array() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:128
  7. {closure}() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:128
  8. Pimple->offsetGet() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:15
  9. {closure}() phar:///var/www/silex/silex.phar/vendor/pimple/pimple/lib/Pimple.php:81
 10. Silex\\Provider\\{closure}() phar:///var/www/silex/silex.phar/vendor/pimple/pimple/lib/Pimple.php:120

此问题也是posted on GitHub

2 个答案:

答案 0 :(得分:0)

解决方案是使用Composerautoload.php

答案 1 :(得分:0)

使用这种方法,你的twig.class_path可能需要vendor/twig/twig/lib(额外的twig目录)......

但twig.class_path实际上是不必要的,使用作曲家,这是更好的方法(如kuboslav笔记)。