2

I created a module with the pluginfactory generator. The module is used for generating a zip file with all the files belonging to a project.

In the composer.json file, I added the following:

"autoload": {
    "psr-4": {
      "zipassetscraft3module\\": "modules/zipassetscraft3module"
    }
  },

in the config/app.php I added:

'modules' => [
      'zip-assets-craft-3-module' => \modules\zipassetscraft3module\ZipAssetsCraft3Module::class,
    ],

In the file controllers/DefaultController.php I added a function called actionDownload() as well as a download() function in the file services/ZipAssetsCraft3ModuleService.php

On the website I have a form with the following url as action: https://default.com/actions/zip-assets-craft-3-module/default/download

When I submit the form, I get an error:

Invalid Configuration – yii\base\InvalidConfigException Failed to instantiate component or class "modules\zipassetscraft3module\ZipAssetsCraft3Module".

Caused by: ReflectionException Class modules\zipassetscraft3module\ZipAssetsCraft3Module does not exist

I have dumped the composer autoload, but I don't know why it's not working. Any ideas what I need to change to get this working?

This is the file structure of the module: enter image description here

So the error message says, there is a class missing, in which file is this class looked for?

obs
  • 509
  • 4
  • 11
  • Try to remove \modules from \modules\zipassetscraft3module\ZipAssetsCraft3Module::class in your config/app.php – Oli May 28 '19 at 14:05
  • You don't mention bootstrapping your module; that might be what you're missing. You should have a bootstrap array in config/app.php, add the module "key" you created above to the bootstrap array: 'bootstrap' => ['zip-assets-craft-3-module'],... – Jalen Davenport May 29 '19 at 21:03
  • @Oli that doesn't change anything unfortunately – obs Jun 03 '19 at 10:28
  • @JalenDavenport when I do this, the error message appears immediately and not only when I call the action. I updated my question and added a screenshot with the file structure – obs Jun 03 '19 at 10:32
  • 1
    @obs ah so you're referencing a Class by the name of ReflectionException in your ZipAssetsCraft3Module.php file that PHP can't find. Any chance you could post the contents of that file or at least the snippet that contains ReflectionException? – Jalen Davenport Jun 03 '19 at 13:57
  • @JalenDavenport the error message says "Class modules\zipassetscraft3module\ZipAssetsCraft3Module does not exist in /www/[...]/vendor/yiisoft/yii2/di/Container.php at line 431". I'm afraid this doesn't help much. In the docs, there is a section about the "Module class": https://docs.craftcms.com/v3/extend/module-guide.html#the-module-class. I don't have a file Module.php in my module, do I need one? – obs Jun 04 '19 at 14:11
  • @obs if you're getting a different error it would be helpful to explain where you're seeing it and what you changed since the original post. Maybe if you could share your whole codebase in a GitHub repo (or something like that) I could take a quick look... Alternatively, you could post something over in the Craft Discord group, as this isn't a question one can easily answer without a lot more info. – Jalen Davenport Jun 04 '19 at 14:25
  • @JalenDavenport the codebase of the module is from https://pluginfactory.io/. I then call this action via a form submit: https://[domain]/actions/zip-assets-craft-3-module/default/download For this I have the function download() in services/ZipAssetsCraft3ModuleService.php – obs Jun 05 '19 at 12:16
  • I found the right paths in the readme.md file. – obs Jul 03 '19 at 11:50

1 Answers1

1

I came across the same issue. So how i solved it is to modify the modules array like this and now the module is loading:

return [
    'modules' => [
        'zip-assets-craft-3-module' => [
            'class' => \modules\zipassetscraft3module\ZipAssetsCraft3Module::class,
        ],
    ],
    'bootstrap' => ['zip-assets-craft-3-module'],
];