[英]PSR-4 Autoloader not recognizing classes in subfolder structure
I am using Slim PHP as the underlaying framework for my app and composer autoload for the loading of my classes. 我将Slim PHP用作应用程序的底层框架,并使用composer autoload来加载类。 In composer i have this psr-4 configuration:
在作曲家我有这个psr-4配置:
"psr-4": {
"App\\": "app/classes/"
}
All my classes are in /app/classes/ folder. 我所有的课程都在/ app / classes /文件夹中。
In my classes folder i have all common classes but module specific classes i have in sub folders. 在我的班级文件夹中,我拥有所有常见的班级,但子文件夹中有模块特定的班级。
From my ../classes/connect.php file i am having this method under the corresponding namespace: 从我的../classes/connect.php文件中,我在相应的名称空间下有此方法:
namespace App;
class connect
{
public function authenticate(){
office\AuthenticationManager::acquireAppToken(200);
}
}
In my subfolder ../classes/office/ i have a file called office.php with this method: 在我的子文件夹../classes/office/中,我有一个名为office.php的文件,使用这种方法:
namespace App\office;
class AuthenticationManager
{
public function acquireAppToken($tid)
{
\App\APIManager\RequestManager::sendPostRequest();
}
}
The above method is calling another method which is located in ../classes/api.php 上面的方法正在调用位于../classes/api.php中的另一个方法
The namespace in that file is 该文件中的名称空间是
namespace App\APIManager;
The problem is that when calling on this last method i get the following error: "\\App\\APIManager\\RequestManager" not found... 问题是,在调用此最后一种方法时,出现以下错误:找不到“ \\ App \\ APIManager \\ RequestManager” ...
I already tried to solve this with composer dump-autoload, but it did not help. 我已经尝试使用composer dump-autoload解决此问题,但没有帮助。 Why is this error happening?
为什么会发生此错误?
If you want to have a class named RequestManager
in App\\APIManager
namespace, then it must be located in APIManager/RequestManager.php
file. 如果要在
App\\APIManager
命名空间中有一个名为RequestManager
的类,则它必须位于APIManager/RequestManager.php
文件中。
It also applies to the AuthenticationManager
class, which should be moved to office/AuthenticationManager.php
它也适用于
AuthenticationManager
类,应将其移至office/AuthenticationManager.php
Have a look at PSR-4 examples . 看一下PSR-4示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.