简体   繁体   中英

php Fatal error: Class 'Slim' not found in

Why this is generating fatal error Slim not found .

index.php

<?php
require "Slim/Slim.php";

// create new Slim instance
$app = new Slim();

// add new Route 
$app->get("/", function () {
    echo "<h1>Hello Slim World</h1>";
});

// run the Slim app
$app->run();

Requested URL

GET : http://localhost/mywebapps/index.php 
GET:  http://localhost/mywebapps/

My Directory structure on windows

www/mywebapps/
             Slim- slim frameworks folder(Having Slim.php and other files also)
             index.php - php file

what is i am doing wrong please help me guy's.

I have found the solution by doing the this.

<?php
require "Slim/Slim.php";

\Slim\Slim::registerAutoloader();

// create new Slim instance
$app = new \Slim\Slim();

Use this code after importing Slip.php

use \Slim\Slim AS Slim;
$app = new Slim();

as stated in Slim documentation , you need to call autoloader:

<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM