如何在Slim框架中修复此错误?

时间:2016-09-22 14:09:35

标签: slim

我在wamp服务器中使用composer安装了Slim框架。

但显示以下错误。

我是Slim的新手。

超薄应用程序错误 由于以下错误,应用程序无法运行:

  

详细

     

类型:ErrorException代码:2消息:   file_get_contents(templates / index.html):无法打开流:否   这样的文件或目录文件:   d:\瓦帕\ WWW \ photometa \厂商\树枝\树枝\ lib中\枝条\装载机\ Filesystem.php   行:131跟踪

     

0 [内部功能]:Slim \ Slim :: handleErrors(2,' file_get_conten ...',' D:\ wamp \ www \ pho ...' ,131,数组)

     

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

     

的file_get_contents('模板/索引...&#39)

     

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

     

Twig_Loader_Filesystem->的getSource('的index.html&#39)

     

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-&gt; fetch(&#39; index.html&#39;,NULL)< / H1>      

6 D:\ wamp \ www \ photometa \ vendor \ slim \ slim \ Slim \ Slim.php(757):Slim \ View-&gt; display(&#39; index.html&#39;)

     

7 D:\ wamp \ www \ photometa \ public \ index.php(33):Slim \ Slim-&gt; render(&#39; index.html&#39;)

     

8 [内部函数]:{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-&gt; dispatch()

     

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

     

超薄\ Slim-&GT;()调用

     

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

     

超薄\中间件\闪速&GT;()调用

     

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

     

超薄\中间件\ MethodOverride-&GT;()调用

     

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

     

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

     

16 {main}

这是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 个答案:

答案 0 :(得分:1)

试试这个:

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