dqwh1218 2016-01-16 10:12
浏览 80

致命错误:在'vendor \ slim \ views \ Twig.php中找不到类'Slim \ Views'

I'm building a simple website in PHP with Slim Framework and Twig template engine.

I've installed Slim and Twig with Composer in the Command Line.

This is my index.php

<?php
require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('Europe/Copenhagen');

$app = new Slim\App( array (
    'view' => new Slim\Views\Twig()
));


$view = $app->view();
$view->parserOptions = array(
    'debug' => true
);

$view->parserExtensions = array(
    new \Slim\Views\Twig(),
);

$app->get('/', function() use($app){
    $app->render('about.twig');
});

$app->get('/contact', function() use($app){
    $app->render('contact.twig');
});

$app->run();

?>

The error message is:

Fatal error: Class 'Slim\Views' not found in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\simple-php-website\vendor\slim\views\Twig.php on line 46

It works without the Twig framework. So I guess the trouble is on loading the Twig. I've tried different variations of this line:

'view' => new Slim\Views\Twig()

But what confuses me is, that the error message is referring to line 46 in the Twig.php - which is in the core of slim.

I've tried reinstalling Twig and Slim several times.

Any suggestions what is wrong?

Much appreciated!

EDIT This is from my composer.json

{
"name": "tyf5vl/simple-php-website",
"authors": [
    {
        "name": "My Name",
        "email": "my@mail.com"
    }
],
"require": {
    "monolog/monolog": "^1.17",
    "slim/slim": "^3.1",
    "twig/twig": "^1.23",
    "slim/views": "^0.1.3"
}
}
  • 写回答

1条回答 默认 最新

  • douyinjiao9351 2016-10-08 18:25
    关注

    http://www.slimframework.com/docs/features/templates.html states that ONLY view is this -> composer require slim/twig-view you should have final file as

    {
        "require": {
            "slim/slim": "^3.5",
            "slim/twig-view": "^2.1"
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站