为什么即使在正确声明命名空间后我也会收到错误?

时间:2017-02-11 18:18:42

标签: php json composer-php php-5.6

这是我的文件夹结构

folder structure

这是我的composer.json代码

{
"name": "hashstar/hashstar",
"description": "Online shopping",
"type": "project",
"license": "private",
"authors": [
    {
        "name": "Akshay Shrivastav",
        "email": "akshayshrivastav866@gmail.com"
    }
],
"minimum-stability": "dev",
"require": {
    "php": ">=5.5.0"
},
"autoload": {
    "psr-4": {
        "modules\\": "/"
    }
  }
}

使用此代码,我已成功生成供应商文件夹中的autoload.php内容。

I have a file name HelloWorld.php in modules folder

在下面显示快照的根目录中,我有一个名为index.php的文件,代码如下:

<?php
    require_once __DIR__ . '/vendor/autoload.php';
    use modules\HelloWorld\Greetings;
    echo Greetings::sayHelloWorld();
?>

运行此代码后,我收到此类错误

error

我不知道错误是什么我一直在google&amp;从最近几个小时做各种事情。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

实际上,我收到的错误是我没有做两件事。

1.) Using vendor name folder structure with namespaces in it.
2.) I wasn't using dump-autoload thing. After doing these two things finally my code is working. Thanks for the help :)
相关问题