作曲家PHP自动加载不起作用



对于我的webpanel,我创建了一个Libary,我可以通过Composer毫无问题地安装它,但是当我想实现界面称为视图时,我收到了以下错误消息:

`2017/06/22 16:00:22 [error] 23179#23179: *120 FastCGI sent in stderr: "PHP 
message: PHP Fatal error:  Interface 'RaphaelScheinkoenigWebLibView' 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 libary:

`{
 "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/"
 }
 } 
 }`

Libary的文件夹树:http://prntscr.com/fmwu6o

view.php libary:

`<?php
namespace RaphaelScheinkoenigWebLib;
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;
}`

dasbordview.php 在WebPanel中实现:

require_once ($_SERVER["P_PATH"]."vendor/autoload.php");
class DashboardView implements RaphaelScheinkoenigWebLibView
{
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;
}}

`谢谢您提前的帮助。

Raphael Scheinkoenig

对于psr-0,您应该将RaphaelScheinkoenigWebLibView (view.php(放入src/RaphaelScheinkoenig/WebLib文件夹中。

fyi,psr-0已被标记为弃用。因此,只需使用psr-4即可。如果您使用psr-4,则不需要制作src/RaphaelScheinkoenig/WebLib文件夹。

调整composer.json中的自动加载配置以使用PSR-4代替PSR-0(如注释中所建议(:

{
    "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/"
         }
     } 
}

供参考,请参见

  • http://www.php-fig.org/psr/psr-0/
  • http://www.php-fig.org/psr/psr-4/
  • https://stackoverflow.com/a/24869629/1172545

最新更新