2016-02-03 70 views
-1

我是根據Slim Documentation安裝。之後我在下面創建的index.php file.Given安裝苗條3:獲取致命錯誤苗條3框架

的index.php:

<?php 

require 'vendor/autoload.php'; 

$app = new Slim\App(); 

$app->get('/hello/{name}', function ($request, $response, $args) { 
    $response->write("Hello, " . $args['name']); 
    return $response; 
}); 

$app->run(); 

但是當我運行在http://localhost:8000的應用程序,然後我得到一個致命error.I已經搜索並獲得stackoverflow.Those一些解決方案是:

但是,這些解決方案沒有解決我的problem.Have它的任何具體的解決方案?

錯誤:

Fatal error: Class 'Slim\App' not found in C:\xampp\htdocs\api\index.php on line 5

我的目錄格式:

enter image description here

更新: 供應商/ autoload.php:

<?php 

// autoload.php @generated by Composer 

require_once __DIR__ . '/composer' . '/autoload_real.php'; 

return ComposerAutoloaderInit98cfb2e091de2f633f87c81d16402aec::getLoader(); 

廠商forlder: enter image description here

+0

什麼是您的致命錯誤? – Drudge

+1

顯示供應商目錄中的內容,並顯示供應商/ autoload.php中的內容。 – ksimka

+0

請勿將您的index.php放入供應商文件夾,它僅用於依賴關係。 –

回答

1

的問題是,你必須手動下載並提取到修身htdocs\api\Slim

它不是由作曲家牽強,那麼這將駐留在供應商的文件夾(vendor/slim/slim)和自動加載會自動工作。


添加修身您composer.json並再次運行composer install

{ 
    "require": { 
     "slim/slim": "^3.0" 
    } 
} 

您已經要求作曲家自動加載,所以depenendency應該找到並加載它取了。

參考:http://docs.slimframework.com/start/get-started/

+1

Slim 3沒有自動加載器了。唯一的方法是使用Composers自動加載器。 –

+0

好的,我刪除了Slim 2的解決方案。 –