0

Here is my project's structure:

app/
   Life/
      Forms
         Formhandler.php
      Page
         Pagehandler.php
   start.php

vendor/
   composer/
       autoload.php
index.php

The index.php requires start.php which then requires the composer autoload.php:

    //start.php
<?php
        require_once __DIR__ . '/../vendor/autoload.php';

This is a working structure, until I added Twig into the composer. Here's is what my composer.json looks like now:

{
    "autoload": {
        "psr-4": {
            "Life\\" : "app/Life"
        }
    },
    "require": {
        "twig/twig" : "~1.0"
    }
}

I far as I know, Twig doesn't support psr-4 for now and the only way I know is to require it in composer this way but with the "require" included I encounter an error like: Class 'Life\Page\Twig_Autoloader' not found.

What am I missing here?

shaNnex
  • 1,043
  • 2
  • 19
  • 34

1 Answers1

2

Which code does trigger this error?

Please pay attention to which namespace you are in! It will affect the resolution of class names.

For example your error might be triggered if you are inside namespace Life\Page and are using new Twig_Autoloader(). That class should either be imported via uses or used as new \Twig_Autoloader().

Sven
  • 69,403
  • 10
  • 107
  • 109
  • Also: you need not use twig's autoloader, if you include composers `vendor/autoload.php` it'll take care of it for you. Your project uses psr4, twig uses psr0, and composer can handle it. – Maerlyn Feb 11 '15 at 17:24
  • Just take case about backslash "\" before `Twig_Loader_Filesystem` and `Twig_Environment` – cystbear Mar 09 '16 at 11:14