First attempt at making a module. So far all I've done is try to change the namespace of the template that was included with my freshly installed craft 3.0.23.1 project.

Was following the official docs (https://docs.craftcms.com/v3/extend/module-guide.html#set-up-the-basic-file-structure) and spend a few hours trying to figure this out on various searches here and elsewhere.

So in the file '/modules/Module.php' I changed

namespace modules;

to

namespace banana\modules;

, then in '/composer.json' changed:

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

to

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

Then in Terminal, ran the command 'composer dump-autoload -a' in the project folder. Reload the page and I get the error. Other than just doing the setup wizard, i haven't touched any other files in the project.

It's a bit difficult without seeing all of your code, but I'm going to guess that you also need to make changes in your config/app.php to make the namespace changes you're making.

So two things I'd recommend... first, you can generate your module's framework here: https://pluginfactory.io/

...and second I wrote up a tutorial on creating a module in the Enhancing a Craft CMS 3 Website with a Custom Module article.

  • I'll give it a try. Thanks – MrMagicalBananaful Sep 10 at 17:32
  • Ah, the problem was when i set the Module ID in 'config/app.php'. I thought the value of the 'class' key was using the path to the class file. But I see it's actually '{namespace}\{class name}::class'. Thanks @andrew.welch for pointing me in the right direction. – MrMagicalBananaful Sep 10 at 18:00

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.