0

I'm getting:

Fatal error: Class 'Twig_Loader_Filesystem'

<?php

require_once "library/Symfony/Component/ClassLoader/UniversalClassLoader.php";

use Symfony\Component\ClassLoader\UniversalClassLoader;

$loader = new UniversalClassLoader();
$loader->registerNamespace("Symfony\Component", "library/Symfony/Component");
$loader->registerPrefix("Twig_", "library/Twig");
$loader->register();

$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array(
    'cache' => '',
));

?>

The Twig folder is in library folder. Have I missunderstood on how to use the component?

Squazic
  • 3,670
  • 3
  • 26
  • 40
John
  • 2,900
  • 8
  • 36
  • 65
  • Fatal error: Class 'Twig_Loader_Filesystem' not found in C:\wamp\www\Dropbox\bootstrap.php on line 23 – John Nov 29 '12 at 19:57

1 Answers1

1
  1. Are you sure your path is correct?
  2. Try to use __DIR__ . '/library'
  3. Try to use DebugUniversalClassLoader to pin down the problem - you can catch a RuntimeException and see which file it actually tries to load.

EDIT:

Correct solution: If you try to load PEAR-style classes with prefix Twig_ from '/library/Twig', you should point it to '/library', because Twig_ prefix itself will be used as a directory name inside /library

scriptin
  • 3,060
  • 1
  • 24
  • 33
  • The path is "ROOT"-folder "library" "Twig", the Symfony is placed in "library" folder as well, so yes the path must be correct. – John Nov 29 '12 at 20:09
  • Try to use `$loader->registerPrefix("Twig_", __DIR__ . "/library");` instead. You can how it choses the file here: https://github.com/symfony/ClassLoader/blob/master/UniversalClassLoader.php#L297 – scriptin Nov 29 '12 at 20:15