Twig and Namespaces

Asked

Viewed 252 times

2

Hello, I’m having a hard time implementing the Twig in my project MVC, I’m using namespaces, autoloader all that stuff from PSR-0. I would like the hope of you to implement why I’m already freaking out. rs

public function render($file, $data = null){        
    require_once LIB . '/Twig/Autoloader.php';
    \Twig_Autoloader::register();               

    $loader = new \Lib\Twig_Loader_Filesystem('/path/to/templates');
    $twig = new Twig_Environment($loader, array(
        'cache' => '/path/to/compilation_cache',
    ));
}

This is my method that will render the template, so far I have the following error:

Exception: Controller Twig_Autoloader not found. in C:\UwAmp\www\system\engine\autoload.php

  • If you are using PSR-0 why not simply include the vendor/autoload.php and give a use in the Twig class ?

  • I tried to do this, but it starts from the error in other classes inside Twig, I don’t know what interface blah blah. rs

1 answer

3


Easier you use Composer to autoload, just run

composer require "twig/twig:1.*"

and then include the autoload generated by Composer:

require_once '/path/to/vendor/autoload.php';

Twig has a very complete documentation that explains how to installation for commiserate

Browser other questions tagged

You are not signed in. Login or sign up in order to post.