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"
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分