简体   繁体   中英

PHP Composer Autoload not loading classes

Somehow I have problems with the composer autoloader. I am using Propel as ORM framework. My folder structure looks the following:

src/BestFreeSites/App
- /Map
- /Base
src/BestFreeSites/Auth
src/BestFreeSites/Framework

I want to include all files using composer autoload. My composer.json file looks like this:

"autoload": {
    "classmap": [
    "src/BestFreeSites/App/",
    "src/BestFreeSites/App/Base/",
    "src/BestFreeSites/App/Map/",
    "src/BestFreeSites/Auth/",
    "src/BestFreeSites/Framework/"
]
}

The classes in the first three folders are accessible, but not the classes in Auth and Framework (created by me). I've also set the correct namespaces. Let's take AuthController.php (in folder Auth) as an example:

namespace BestFreeSites\Auth;

public class AuthController
{

    public function register($args)
    {
        return $args;
    }
}

And I'm trying to include the file with 'use', like this:

use \BestFreeSites\App\SiteQuery;
use \BestFreeSites\App\UserQuery;
use \BestFreeSites\App\RatingQuery;
use \BestFreeSites\Auth\AuthController as Auth;
use \BestFreeSites\Framework\Abstract;

Only the last two imports are not working. I have already dumped my autoload and reloaded it ( composer dump-autoload )

Could anyone please guide me in the right direction?

Thanks in advance :)

Kind regards, David

where is your real \\BestFreeSites\\Auth\\AuthController class located? Can you provide script level directory hierarchy?

And did you require your vendor/autoload.php file correctly?

Or if you just want to set your psr4 autoloader, then follow the following code for your composer.json file.

{
    "autoload": {
        "psr-4": {
            "BestFreeSites\\": "src/BestFreeSites"
        }
    }
}

//use your AuthController class
$autoController = new \BestFreeSites\Auth\AuthController();

It's pretty straightforward. I guess, it helps.

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