Search code examples
phpsymfonytwigautoloader

Symfony autoloader component


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?


Solution

    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