Composer PHP自动加载不工作
对于我的WebPanel,我创建了一个库,我可以通过composer毫无问题地安装它,但当我想要实现名为View的接口时,我收到了以下错误消息:Composer PHP自动加载不工作,php,json,composer-php,Php,Json,Composer Php,对于我的WebPanel,我创建了一个库,我可以通过composer毫无问题地安装它,但当我想要实现名为View的接口时,我收到了以下错误消息: `2017/06/22 16:00:22 [error] 23179#23179: *120 FastCGI sent in stderr: "PHP message: PHP Fatal error: Interface 'RaphaelScheinkoenig\WebLib\View' not found in /var/www/site/a
`2017/06/22 16:00:22 [error] 23179#23179: *120 FastCGI sent in stderr: "PHP
message: PHP Fatal error: Interface 'RaphaelScheinkoenig\WebLib\View' not
found in /var/www/site/app/view/DashboardView.php on line 10" while reading
response header from upstream, client: 88.xx.xxx.xxx, server:
xxxxxx.xxxxxx.xxxxx, request: "GET /dashboard HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "xxxxxx.xxxxxx.xxxxx"`
图书馆的Composer.json:
`{
"name": "raphaelscheinkoenig/weblib",
"description": "WebLib",
"license": "MIT",
"authors": [
{
"name": "Raphael Scheinkoenig",
"email": "scheinkoenig.raphael@gmail.com"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=7.0.0"
},
"autoload": {
"psr-0": {
"RaphaelScheinkoenig\\WebLib\\": "src/"
}
}
}`
库的文件夹树:
图书馆的View.php:
`<?php
namespace RaphaelScheinkoenig\WebLib;
interface View{
public function getTitle():string;
public function getCSSPlugins():string;
public function getJsHeadScripts():string;
public function getContent():string;
public function getJSPlugins():string;
public function getActiveHeader():string;
public function getPluginInitialization():string;
public function getGoogleAnalytics():string;
public function getHeaderKey():string;
public function getFooter():string;
public function getPageHeader():string;
}`
`对于psr-0
,您应该将RaphaelScheinkoenig\WebLib\View
(View.php)放入src/RaphaelScheinkoenig/WebLib
文件夹中
仅供参考,psr-0
已标记为已弃用。所以,只需使用psr-4即可。如果你使用psr-4
你不需要把src/RaphaelScheinkoenig/WebLib
文件夹。对于psr-0
,你应该把RaphaelScheinkoenig\WebLib\View
(View.php)放到src/RaphaelScheinkoenig/WebLib
文件夹中
仅供参考,psr-0
已标记为已弃用。所以,只需使用psr-4即可。如果您使用psr-4
,则无需创建src/RaphaelScheinkoenig/WebLib
文件夹。
有关参考,请参阅
调整composer.json
中的自动加载配置,以使用PSR-4而不是PSR-0(如注释中所示):
有关参考,请参阅
你把View.php
放在哪里了?共享文件夹的树。在上面添加了库的树,然后您可能需要使用psr-4
而不是psr-0
。在composer.json文件中更改它,然后重建自动加载器。您将View.php
放在哪里?共享文件夹的树。在上面添加了库的树,然后您可能需要使用psr-4
而不是psr-0
。在composer.json文件中更改它,然后重新生成自动加载程序。
require_once ($_SERVER["P_PATH"]."vendor/autoload.php");
class DashboardView implements RaphaelScheinkoenig\WebLib\View
{
public function getTitle():string{
return "Dashboard";
}
public function getCSSPlugins():string{
$str = '<link rel="stylesheet" href="'.$_SERVER['P_PATH'].'assets/globals/css/plugins.css">';
return $str;
}
public function getPageHeader():string{
return "Dashboard";
}
public function getJsHeadScripts():string{
return "";
}
public function getContent():string{
// TODO: Implement getContent() method.
}
public function getJSPlugins():string{
$str = '<script src="'.$_SERVER['P_PATH'].'assets/admin1/js/layout.js"></script>';
return $str;
}
public function getActiveHeader():string{
return "Dashboard";
}
public function getPluginInitialization():string{
$str = "<script>
$(document).ready(function () {
Layout.init();
});
</script>";
return $str;
}
public function getGoogleAnalytics():string{
$str = "";
return $str;
}
public function getHeaderKey():string{
return "Dashboard";
}
public function getFooter():string{
$str = '';
return $str;
}}
{
"name": "raphaelscheinkoenig/weblib",
"description": "WebLib",
"license": "MIT",
"authors": [
{
"name": "Raphael Scheinkoenig",
"email": "scheinkoenig.raphael@gmail.com"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=7.0.0"
},
"autoload": {
"psr-4": {
"RaphaelScheinkoenig\\WebLib\\": "src/"
}
}
}