1
votes

I installed Slim framwork using composer in wamp server.

But displays following error.

I am new to Slim.

Slim Application Error The application could not run because of the following error:

Details

Type: ErrorException Code: 2 Message: file_get_contents(templates/index.html): failed to open stream: No such file or directory File: D:\wamp\www\photometa\vendor\twig\twig\lib\Twig\Loader\Filesystem.php Line: 131 Trace

0 [internal function]: Slim\Slim::handleErrors(2, 'file_get_conten...', 'D:\wamp\www\pho...', 131, Array)

1 D:\wamp\www\photometa\vendor\twig\twig\lib\Twig\Loader\Filesystem.php(131):

file_get_contents('templates/index...')

2 D:\wamp\www\photometa\vendor\twig\twig\lib\Twig\Environment.php(397):

Twig_Loader_Filesystem->getSource('index.html')

3 D:\wamp\www\photometa\vendor\slim\views\Twig.php(87): Twig_Environment->loadTemplate('index.html')

4 D:\wamp\www\photometa\vendor\slim\slim\Slim\View.php(255): Slim\Views\Twig->render('index.html', NULL)

5 D:\wamp\www\photometa\vendor\slim\slim\Slim\View.php(243): Slim\View->fetch('index.html', NULL)

6 D:\wamp\www\photometa\vendor\slim\slim\Slim\Slim.php(757): Slim\View->display('index.html')

7 D:\wamp\www\photometa\public\index.php(33): Slim\Slim->render('index.html')

8 [internal function]: {closure}()

9 D:\wamp\www\photometa\vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)

10 D:\wamp\www\photometa\vendor\slim\slim\Slim\Slim.php(1357): Slim\Route->dispatch()

11 D:\wamp\www\photometa\vendor\slim\slim\Slim\Middleware\Flash.php(85):

Slim\Slim->call()

12 D:\wamp\www\photometa\vendor\slim\slim\Slim\Middleware\MethodOverride.php(92):

Slim\Middleware\Flash->call()

13 D:\wamp\www\photometa\vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67):

Slim\Middleware\MethodOverride->call()

14 D:\wamp\www\photometa\vendor\slim\slim\Slim\Slim.php(1302): Slim\Middleware\PrettyExceptions->call()

15 D:\wamp\www\photometa\public\index.php(37): Slim\Slim->run()

16 {main}

This is index.php

<?php
require '../vendor/autoload.php';

// Prepare app
$app = new \Slim\Slim(array(
    'templates.path' => '../templates',
));

// Create monolog logger and store logger in container as singleton 
// (Singleton resources retrieve the same log resource definition each time)
$app->container->singleton('log', function () {
    $log = new \Monolog\Logger('slim-skeleton');
    $log->pushHandler(new \Monolog\Handler\StreamHandler('../logs/app.log', \Monolog\Logger::DEBUG));
    return $log;
});

// Prepare view
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array(
    'charset' => 'utf-8',
    'cache' => realpath('../templates/cache'),
    'auto_reload' => true,
    'strict_variables' => false,
    'autoescape' => true
);
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension());

// Define routes
$app->get('/', function () use ($app) {
    // Sample log message
    $app->log->info("Slim-Skeleton '/' route");
    // Render index view
    $app->render('index.html');
});

// Run app
$app->run();
1
where is your index.html file located? - Pipe
index.html is rootfolder/public/. - Eric Chan
I have the same error message. It's probably the new twig version 1.25.0. It worked with 1.24.2 Investigating right now. - Largo
I can't find the error in Twig v1.25.0. The problem seems to arise in /composer_modules/extras/slim/Extras/Views/Twig.php on line 97. ($env->loadTemplate($template). Solution: Downgrade to Twig v1.24.2,. If you use composer you only need to open composer.json and change the line to "twig/twig": "1.24.2", and then run composer update in the terminal - Largo

1 Answers

1
votes

Try this :

$app = new \Slim\Slim(array(
    'templates.path' => __DIR__ . '/../templates/',
));