doujiang5211 2017-06-22 15:46
浏览 188
已采纳

Composer PHP自动加载不起作用

for my WebPanel i created a libary, i can install it via composer without problems but when i want to implement my interface called View i got the following error message:

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

Folder Tree of the libary: http://prntscr.com/fmwu6o

View.php of the libary:

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

DasbordView.php Implementation in the WebPanel:

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;
}}

` Thank you for your help in advance.

Raphael Scheinkoenig

  • 写回答

2条回答 默认 最新

  • duanfei7508 2017-06-23 00:57
    关注

    For psr-0, you should put RaphaelScheinkoenig\WebLib\View (View.php) into src/RaphaelScheinkoenig/WebLib folder.

    Fyi, psr-0 has been marked as deprecated. So, just use psr-4. And if you use psr-4 you don't need to make src/RaphaelScheinkoenig/WebLib folder.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • doudu5498 2017-06-24 08:16
    关注

    Adjust the autoloading configuration in composer.json to use PSR-4 instead of PSR-0 (as already suggested in the comments):

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

    For reference, see

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 (关键词-聊天软件)
  • ¥15 求大家看看这个编程的编法没有思路啊
  • ¥20 WSL打开图形化程序子窗口无法点击
  • ¥15 Jupyter Notebook 数学公式不渲染
  • ¥20 ERR_CACHE_MISS 确认重新提交表单
  • ¥20 关于vba使用HTMLfile执行js函数问题
  • ¥60 悬赏求解,通过实时现场摄像头的视频图像识别其他对家打出的麻将牌,识别麻将牌,识别牌墙位置,通过识别对家打出了什么牌
  • ¥15 关于#GPU jetson#的pcie驱动开发问题,如何解决?
  • ¥15 stm32f103zet6 串口5无法收发数据
  • ¥15 关于C语言使用线程队列实现多线程并发