gonzalon gonzalon - 6 months ago 122
PHP Question

Error using Slim framework and Twig template

I'm trying to make Slim work with Twig template system, this is part of my

index.php


// Twig [Template]
require 'Extras/Views/Twig.php';
TwigView::$twigDirectory = __DIR__ . '/vendor/Twig/lib/Twig/';

//Slim
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim(array(
'view' => $twigView
));


And this is my structure

Extras
|_Views
|_Twig.php
Slim
templates
vendor
|_Twig
|_lib
|_Twig
index.php


I try several times with other configurations and searching buy I ALLWAYS get this error:

Fatal error: Class 'Slim\View' not found in C:\wamp\www\slim\Extras\Views\Twig.php on line 43


Can anyone help me here? All the examples I had found was using composer

Answer

Ok, I solve it. This is the solution:

// Slim PHP
require "Slim/Slim.php";
\Slim\Slim::registerAutoloader();

// Twig
require "Twig/lib/Twig/Autoloader.php";
Twig_Autoloader::register();

// Start Slim.
/** @var $app Slim */
$app = new \Slim\Slim(array(
    "view" => new \Slim\Extras\Views\Twig()
));

And this is my structure now.

Slim
|_Extras
    |_Views
        |_Twig.php
|_Slim
templates
Twig
 |_lib
   |_Twig
      |_Autoloader.php
index.php

¡I hope this help someone else!

Comments