vardius
vardius

Reputation: 6546

why my class can not be found?

Doing some php and the root directory looks like this:

web/
    -index.php
src/
    -Controllers/
        -IndexController.php
    -Services/
        -IpService.php

class IpService has namespace Service i added this namespace to autoload:

"autoload": {
    "psr-0": {
        "Service\\": "src/"
    }
}

and in the IndexController.php im doing this:

use Services\IpService;

$app['ip_service'] = function () {
    return new IpService();
};

but when i call $app['ip_service']->get() i'm getting the error:

Fatal error: Class 'Services\IpService' not found in E:\xampp\htdocs\src\Controllers\IndexController.php on line 18

Upvotes: 0

Views: 94

Answers (1)

Chris Rasco
Chris Rasco

Reputation: 2731

Your autoload field for composer references a namespace named "Service" but your folder structure and IndexController.php reference "Services".

Upvotes: 1

Related Questions