[英]class not found exception on Lumen project in shared hosting
I have developed API using Lumen framework and using separately created composer package which I'm planning to use both on Lumen (API) and Laravel (Web site). 我已经使用Lumen框架并使用单独创建的composer程序包开发了API,我计划在Lumen(API)和Laravel(网站)上同时使用。
However I get: 但是我得到:
Class 'Author\\Package\\Models\\ProductItem' not found
找不到类“作者\\包装\\模型\\产品项”
Locally everything is working (using same Apache and PHP version). 在本地,一切正常(使用相同的Apache和PHP版本)。 My directory structure is:
我的目录结构是:
|
\_ api (Lumen code)
|
\_ model\
| \_ src\
| | \_ migrations\
| | |
| | \_ models\
| | | \_ ProductItem.php
| | |...
| |
| \_ composer.json
|
\_ www (Laravel code)
in api\\composer.json
I have: 在
api\\composer.json
我有:
...
"autoload": {
"psr-4": {
"App\\": "app/",
"Author\\Package\\": "../model/src"
}
},
...
Only difference between local and hosting configuration is version of Composer (local is 1.5.2 and remote is 1.4.2). 本地配置和托管配置之间的唯一区别是Composer的版本(本地为1.5.2,远程为1.4.2)。
Your namespace or your PSR-4 mapping is incorrect. 您的名称空间或PSR-4映射不正确。
When your class contains Models
with uppercase M in its namespace Author\\Package\\Models\\ProductItem
it should be located in ./model/src/Models/ProductItem.php
(also uppercase M). 当您的类在其命名空间
Author\\Package\\Models\\ProductItem
包含具有大写M的Models
,它应该位于./model/src/Models/ProductItem.php
(也为大写M)。 So both namespace and folder name must match exactly. 因此,名称空间和文件夹名称必须完全匹配。 On Windows/Mac this is usually not a problem, because the filesystem is case-insensitive, but on a Linux-based host this will cause problems.
在Windows / Mac上,这通常不是问题,因为文件系统不区分大小写,但是在基于Linux的主机上,这会引起问题。
Alternatively you can change your PSR-4 autoloader: 另外,您可以更改PSR-4自动装带器:
"autoload": {
"psr-4": {
"Author\\Package\\Models\\": "../model/src/models"
}
}
You would have to do that for every directory that does not match your namespace. 您将必须为每个与名称空间都不匹配的目录执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.