1

我正在尝试使用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

这个问题也发布在 GitHub 上

4

2 回答 2

0

解决方案是使用Composerautoload.php.

于 2012-05-22T11:02:36.683 回答
0

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

但是 twig.class_path 实际上是不必要的,对于 composer,这是更好的方法(如 kuboslav 注释)。

于 2015-05-09T11:39:56.627 回答